1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/material.dart';
6import 'package:flutter_api_samples/material/button_style/button_style.0.dart' as example;
7import 'package:flutter_test/flutter_test.dart';
8
9void main() {
10 testWidgets(
11 'Shows ElevatedButtons, FilledButtons, OutlinedButtons and TextButtons in enabled and disabled states',
12 (WidgetTester tester) async {
13 await tester.pumpWidget(const example.ButtonApp());
14
15 expect(
16 find.byWidgetPredicate((Widget widget) {
17 return widget is ElevatedButton && widget.onPressed == null;
18 }),
19 findsOne,
20 );
21
22 expect(
23 find.byWidgetPredicate((Widget widget) {
24 return widget is ElevatedButton && widget.onPressed != null;
25 }),
26 findsOne,
27 );
28
29 // One OutlinedButton with onPressed null.
30 expect(
31 find.byWidgetPredicate((Widget widget) {
32 return widget is OutlinedButton && widget.onPressed == null;
33 }),
34 findsOne,
35 );
36
37 // One OutlinedButton with onPressed not null.
38 expect(
39 find.byWidgetPredicate((Widget widget) {
40 return widget is OutlinedButton && widget.onPressed != null;
41 }),
42 findsOne,
43 );
44
45 expect(
46 find.byWidgetPredicate((Widget widget) {
47 return widget is TextButton && widget.onPressed == null;
48 }),
49 findsOne,
50 );
51
52 expect(
53 find.byWidgetPredicate((Widget widget) {
54 return widget is TextButton && widget.onPressed != null;
55 }),
56 findsOne,
57 );
58
59 expect(
60 find.byWidgetPredicate((Widget widget) {
61 return widget is FilledButton && widget.onPressed != null;
62 }),
63 findsNWidgets(2),
64 );
65
66 expect(
67 find.byWidgetPredicate((Widget widget) {
68 return widget is FilledButton && widget.onPressed == null;
69 }),
70 findsNWidgets(2),
71 );
72 },
73 );
74}
75

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com