test_widgets.dart 1.46 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Hixie's avatar
Hixie committed
2 3 4
// 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/rendering.dart';
7
import 'package:flutter/widgets.dart';
8

9 10
const BoxDecoration kBoxDecorationA = BoxDecoration(
  color: Color(0xFFFF0000),
11 12
);

13 14
const BoxDecoration kBoxDecorationB = BoxDecoration(
  color: Color(0xFF00FF00),
15 16
);

17 18
const BoxDecoration kBoxDecorationC = BoxDecoration(
  color: Color(0xFF0000FF),
19 20
);

21
class TestBuildCounter extends StatelessWidget {
22 23
  const TestBuildCounter({ Key key }) : super(key: key);

24 25
  static int buildCount = 0;

26
  @override
27
  Widget build(BuildContext context) {
28
    buildCount += 1;
29
    return const DecoratedBox(decoration: kBoxDecorationA);
30 31 32 33
  }
}


34
class FlipWidget extends StatefulWidget {
35
  const FlipWidget({ Key key, this.left, this.right }) : super(key: key);
36 37 38 39

  final Widget left;
  final Widget right;

40
  @override
41
  FlipWidgetState createState() => FlipWidgetState();
42 43
}

44
class FlipWidgetState extends State<FlipWidget> {
45 46 47 48 49 50 51 52
  bool _showLeft = true;

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

53
  @override
54
  Widget build(BuildContext context) {
55
    return _showLeft ? widget.left : widget.right;
56 57 58
  }
}

59
void flipStatefulWidget(WidgetTester tester, { bool skipOffstage = true }) {
60
  tester.state<FlipWidgetState>(find.byType(FlipWidget, skipOffstage: skipOffstage)).flip();
61
}