Skip to content

Commit 333397a

Browse files
authored
Fix Material 3 BottomSheet example (#116112)
fix title
1 parent 322dd06 commit 333397a

File tree

5 files changed

+82
-18
lines changed

5 files changed

+82
-18
lines changed

examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dart

+7-10
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,24 @@
66
77
import 'package:flutter/material.dart';
88

9-
void main() => runApp(const MyApp());
9+
void main() => runApp(const BottomSheetApp());
1010

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});
1513

1614
@override
1715
Widget build(BuildContext context) {
1816
return MaterialApp(
19-
title: _title,
2017
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(),
2320
),
2421
);
2522
}
2623
}
2724

28-
class MyStatelessWidget extends StatelessWidget {
29-
const MyStatelessWidget({super.key});
25+
class BottomSheetExample extends StatelessWidget {
26+
const BottomSheetExample({super.key});
3027

3128
@override
3229
Widget build(BuildContext context) {

examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.1.dart

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,32 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// Flutter code sample for Material Design 3 TextFields.
65
/// Flutter code sample for [showModalBottomSheet].
76
87
import 'package:flutter/material.dart';
98

10-
void main() => runApp(const MyApp());
9+
void main() => runApp(const BottomSheetApp());
1110

12-
class MyApp extends StatelessWidget {
13-
const MyApp({super.key});
11+
class BottomSheetApp extends StatelessWidget {
12+
const BottomSheetApp({super.key});
1413

1514
@override
1615
Widget build(BuildContext context) {
1716
return MaterialApp(
18-
theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true),
17+
theme: ThemeData(
18+
colorSchemeSeed: const Color(0xff6750a4),
19+
useMaterial3: true,
20+
),
1921
home: Scaffold(
2022
appBar: AppBar(title: const Text('Bottom Sheet Sample')),
21-
body: const MyStatelessWidget(),
23+
body: const BottomSheetExample(),
2224
),
2325
);
2426
}
2527
}
2628

27-
class MyStatelessWidget extends StatelessWidget {
28-
const MyStatelessWidget({super.key});
29+
class BottomSheetExample extends StatelessWidget {
30+
const BottomSheetExample({super.key});
2931

3032
@override
3133
Widget build(BuildContext context) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

packages/flutter/lib/src/material/bottom_sheet.dart

+7
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,13 @@ class _BottomSheetSuspendedCurve extends ParametricCurve<double> {
799799
/// ** See code in examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dart **
800800
/// {@end-tool}
801801
///
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+
///
802809
/// See also:
803810
///
804811
/// * [BottomSheet], which becomes the parent of the widget returned by the

0 commit comments

Comments
 (0)