test_widgets.dart 1.44 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/rendering.dart';
7
import 'package:flutter/widgets.dart';
8

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

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

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

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

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


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

  final Widget left;
  final Widget right;

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

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

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

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

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