test_widgets.dart 1.37 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 10 11 12 13 14 15 16 17 18 19

final BoxDecoration kBoxDecorationA = new BoxDecoration(
  backgroundColor: const Color(0xFFFF0000)
);

final BoxDecoration kBoxDecorationB = new BoxDecoration(
  backgroundColor: const Color(0xFF00FF00)
);

final BoxDecoration kBoxDecorationC = new BoxDecoration(
  backgroundColor: const Color(0xFF0000FF)
);

20
class TestBuildCounter extends StatelessWidget {
21 22
  static int buildCount = 0;

23
  @override
24
  Widget build(BuildContext context) {
25
    buildCount += 1;
26 27 28 29 30
    return new DecoratedBox(decoration: kBoxDecorationA);
  }
}


31 32
class FlipWidget extends StatefulWidget {
  FlipWidget({ Key key, this.left, this.right }) : super(key: key);
33 34 35 36

  final Widget left;
  final Widget right;

37
  @override
38
  FlipWidgetState createState() => new FlipWidgetState();
39 40
}

41
class FlipWidgetState extends State<FlipWidget> {
42 43 44 45 46 47 48 49
  bool _showLeft = true;

  void flip() {
    setState(() {
      _showLeft = !_showLeft;
    });
  }

50
  @override
51 52 53 54 55
  Widget build(BuildContext context) {
    return _showLeft ? config.left : config.right;
  }
}

56
void flipStatefulWidget(WidgetTester tester) {
57
  FlipWidgetState state = tester.state(find.byType(FlipWidget));
58 59
  state.flip();
}