set_state_test.dart 1.54 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
class Inside extends StatefulWidget {
9
  @override
10 11
  InsideState createState() => new InsideState();
}
12

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

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

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

30
  final Inside child;
31

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

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

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

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

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

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