set_state_test.dart 1.55 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 9
import 'package:test/test.dart';

class Inside extends StatefulComponent {
10 11
  InsideState createState() => new InsideState();
}
12

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

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

class Middle extends StatefulComponent {
  Middle({ this.child });

29
  final Inside child;
30

31 32 33 34 35
  MiddleState createState() => new MiddleState();
}

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

Adam Barth's avatar
Adam Barth committed
42
  void _handlePointerDown(_) {
43 44
    setState(() { });
  }
45
}
46

47 48
class Outside extends StatefulComponent {
  OutsideState createState() => new OutsideState();
49 50
}

51 52
class OutsideState extends State<Outside> {
  Widget build(BuildContext context) {
53 54 55 56 57 58
    return new Middle(child: new Inside());
  }
}

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