This repository was archived by the owner on Feb 22, 2023. It is now read-only.
File tree 5 files changed +82
-18
lines changed
lib/material/bottom_sheet
test/material/bottom_sheet
packages/flutter/lib/src/material
5 files changed +82
-18
lines changed Original file line number Diff line number Diff line change 6
6
7
7
import 'package:flutter/material.dart' ;
8
8
9
- void main () => runApp (const MyApp ());
9
+ void main () => runApp (const BottomSheetApp ());
10
10
11
- class MyApp extends StatelessWidget {
12
- const MyApp ({super .key});
13
-
14
- static const String _title = 'Flutter Code Sample' ;
11
+ class BottomSheetApp extends StatelessWidget {
12
+ const BottomSheetApp ({super .key});
15
13
16
14
@override
17
15
Widget build (BuildContext context) {
18
16
return MaterialApp (
19
- title: _title,
20
17
home: Scaffold (
21
- appBar: AppBar (title: const Text (_title )),
22
- body: const MyStatelessWidget (),
18
+ appBar: AppBar (title: const Text ('Bottom Sheet Sample' )),
19
+ body: const BottomSheetExample (),
23
20
),
24
21
);
25
22
}
26
23
}
27
24
28
- class MyStatelessWidget extends StatelessWidget {
29
- const MyStatelessWidget ({super .key});
25
+ class BottomSheetExample extends StatelessWidget {
26
+ const BottomSheetExample ({super .key});
30
27
31
28
@override
32
29
Widget build (BuildContext context) {
Original file line number Diff line number Diff line change 2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
- // Flutter code sample for Material Design 3 TextFields.
6
5
/// Flutter code sample for [showModalBottomSheet] .
7
6
8
7
import 'package:flutter/material.dart' ;
9
8
10
- void main () => runApp (const MyApp ());
9
+ void main () => runApp (const BottomSheetApp ());
11
10
12
- class MyApp extends StatelessWidget {
13
- const MyApp ({super .key});
11
+ class BottomSheetApp extends StatelessWidget {
12
+ const BottomSheetApp ({super .key});
14
13
15
14
@override
16
15
Widget build (BuildContext context) {
17
16
return MaterialApp (
18
- theme: ThemeData (colorSchemeSeed: const Color (0xff6750a4 ), useMaterial3: true ),
17
+ theme: ThemeData (
18
+ colorSchemeSeed: const Color (0xff6750a4 ),
19
+ useMaterial3: true ,
20
+ ),
19
21
home: Scaffold (
20
22
appBar: AppBar (title: const Text ('Bottom Sheet Sample' )),
21
- body: const MyStatelessWidget (),
23
+ body: const BottomSheetExample (),
22
24
),
23
25
);
24
26
}
25
27
}
26
28
27
- class MyStatelessWidget extends StatelessWidget {
28
- const MyStatelessWidget ({super .key});
29
+ class BottomSheetExample extends StatelessWidget {
30
+ const BottomSheetExample ({super .key});
29
31
30
32
@override
31
33
Widget build (BuildContext context) {
Original file line number Diff line number Diff line change
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
+
5
+ import 'package:flutter/material.dart' ;
6
+ import 'package:flutter_api_samples/material/bottom_sheet/show_modal_bottom_sheet.0.dart' as example;
7
+ import 'package:flutter_test/flutter_test.dart' ;
8
+
9
+ void main () {
10
+ testWidgets ('BottomSheet can be opened and closed' , (WidgetTester tester) async {
11
+ const String titleText = 'Modal BottomSheet' ;
12
+ const String closeText = 'Close BottomSheet' ;
13
+
14
+ await tester.pumpWidget (
15
+ const example.BottomSheetApp (),
16
+ );
17
+
18
+ expect (find.text (titleText), findsNothing);
19
+ expect (find.text (closeText), findsNothing);
20
+
21
+ // Open the bottom sheet.
22
+ await tester.tap (find.widgetWithText (ElevatedButton , 'showModalBottomSheet' ));
23
+ await tester.pumpAndSettle ();
24
+
25
+ // Verify that the bottom sheet is open.
26
+ expect (find.text (titleText), findsOneWidget);
27
+ expect (find.text (closeText), findsOneWidget);
28
+ });
29
+ }
Original file line number Diff line number Diff line change
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
+
5
+ import 'package:flutter/material.dart' ;
6
+ import 'package:flutter_api_samples/material/bottom_sheet/show_modal_bottom_sheet.1.dart' as example;
7
+ import 'package:flutter_test/flutter_test.dart' ;
8
+
9
+ void main () {
10
+ testWidgets ('BottomSheet can be opened and closed' , (WidgetTester tester) async {
11
+ const String titleText = 'Modal BottomSheet' ;
12
+ const String closeText = 'Close BottomSheet' ;
13
+
14
+ await tester.pumpWidget (
15
+ const example.BottomSheetApp (),
16
+ );
17
+
18
+ expect (find.text (titleText), findsNothing);
19
+ expect (find.text (closeText), findsNothing);
20
+
21
+ // Open the bottom sheet.
22
+ await tester.tap (find.widgetWithText (ElevatedButton , 'showModalBottomSheet' ));
23
+ await tester.pumpAndSettle ();
24
+
25
+ // Verify that the bottom sheet is open.
26
+ expect (find.text (titleText), findsOneWidget);
27
+ expect (find.text (closeText), findsOneWidget);
28
+ });
29
+ }
Original file line number Diff line number Diff line change @@ -799,6 +799,13 @@ class _BottomSheetSuspendedCurve extends ParametricCurve<double> {
799
799
/// ** See code in examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dart **
800
800
/// {@end-tool}
801
801
///
802
+ /// {@tool dartpad}
803
+ /// This sample shows the creation of [showModalBottomSheet] , as described in:
804
+ /// https://m3.material.io/components/bottom-sheets/overview
805
+ ///
806
+ /// ** See code in examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.1.dart **
807
+ /// {@end-tool}
808
+ ///
802
809
/// See also:
803
810
///
804
811
/// * [BottomSheet] , which becomes the parent of the widget returned by the
You can’t perform that action at this time.
0 commit comments