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/scaffold/scaffold.of.1.dart' as example;
7import 'package:flutter_test/flutter_test.dart';
8
9void main() {
10 testWidgets('Verify correct labels are displayed', (WidgetTester tester) async {
11 await tester.pumpWidget(const example.OfExampleApp());
12
13 expect(find.text('Scaffold.of Example'), findsOneWidget);
14 expect(find.text('SHOW BOTTOM SHEET'), findsOneWidget);
15 });
16
17 testWidgets('Bottom sheet can be shown', (WidgetTester tester) async {
18 await tester.pumpWidget(const example.OfExampleApp());
19
20 expect(find.text('BottomSheet'), findsNothing);
21 expect(find.widgetWithText(ElevatedButton, 'Close BottomSheet'), findsNothing);
22
23 // Tap the button to show the bottom sheet.
24 await tester.tap(find.widgetWithText(ElevatedButton, 'SHOW BOTTOM SHEET'));
25 await tester.pumpAndSettle();
26
27 expect(find.text('BottomSheet'), findsOneWidget);
28 expect(find.widgetWithText(ElevatedButton, 'Close BottomSheet'), findsOneWidget);
29 });
30
31 testWidgets('Bottom sheet can be closed', (WidgetTester tester) async {
32 await tester.pumpWidget(const example.OfExampleApp());
33
34 expect(find.text('BottomSheet'), findsNothing);
35
36 // Tap the button to show the bottom sheet.
37 await tester.tap(find.widgetWithText(ElevatedButton, 'SHOW BOTTOM SHEET'));
38 await tester.pumpAndSettle();
39
40 expect(find.text('BottomSheet'), findsOneWidget);
41
42 // Tap the button to close the bottom sheet.
43 await tester.tap(find.widgetWithText(ElevatedButton, 'Close BottomSheet'));
44 await tester.pumpAndSettle();
45
46 expect(find.text('BottomSheet'), findsNothing);
47 });
48}
49

Provided by KDAB

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