set_state_test.dart 1.61 KB
Newer Older
Hixie's avatar
Hixie committed
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Adam Barth's avatar
Adam Barth committed
5
import 'package:flutter_test/flutter_test.dart';
6
import 'package:flutter/widgets.dart';
7 8
import 'package:test/test.dart';

9
class Inside extends StatefulWidget {
10
  @override
11 12
  InsideState createState() => new InsideState();
}
13

14
class InsideState extends State<Inside> {
15
  @override
16
  Widget build(BuildContext context) {
17 18 19 20 21 22
    return new Listener(
      onPointerDown: _handlePointerDown,
      child: new Text('INSIDE')
    );
  }

Adam Barth's avatar
Adam Barth committed
23
  void _handlePointerDown(_) {
24 25 26 27
    setState(() { });
  }
}

28
class Middle extends StatefulWidget {
29 30
  Middle({ this.child });

31
  final Inside child;
32

33
  @override
34 35 36 37
  MiddleState createState() => new MiddleState();
}

class MiddleState extends State<Middle> {
38
  @override
39
  Widget build(BuildContext context) {
40 41
    return new Listener(
      onPointerDown: _handlePointerDown,
42
      child: config.child
43 44 45
    );
  }

Adam Barth's avatar
Adam Barth committed
46
  void _handlePointerDown(_) {
47 48
    setState(() { });
  }
49
}
50

51
class Outside extends StatefulWidget {
52
  @override
53
  OutsideState createState() => new OutsideState();
54 55
}

56
class OutsideState extends State<Outside> {
57
  @override
58
  Widget build(BuildContext context) {
59 60 61 62 63 64
    return new Middle(child: new Inside());
  }
}

void main() {
  test('setState() smoke test', () {
65 66
    testWidgets((WidgetTester tester) {
      tester.pumpWidget(new Outside());
67
      Point location = tester.getCenter(find.text('INSIDE'));
Adam Barth's avatar
Adam Barth committed
68
      TestGesture gesture = tester.startGesture(location);
69
      tester.pump();
Adam Barth's avatar
Adam Barth committed
70
      gesture.up();
71 72
      tester.pump();
    });
73
  });
Adam Barth's avatar
Adam Barth committed
74
}