From 333397a0ed6972cc703721b8ed7ec34b3ed87e26 Mon Sep 17 00:00:00 2001 From: Taha Tesser Date: Wed, 30 Nov 2022 04:08:21 +0200 Subject: [PATCH] Fix Material 3 `BottomSheet` example (#116112) fix title --- .../show_modal_bottom_sheet.0.dart | 17 +++++------ .../show_modal_bottom_sheet.1.dart | 18 +++++++----- .../show_modal_bottom_sheet.0_test.dart | 29 +++++++++++++++++++ .../show_modal_bottom_sheet.1_test.dart | 29 +++++++++++++++++++ .../lib/src/material/bottom_sheet.dart | 7 +++++ 5 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 examples/api/test/material/bottom_sheet/show_modal_bottom_sheet.0_test.dart create mode 100644 examples/api/test/material/bottom_sheet/show_modal_bottom_sheet.1_test.dart diff --git a/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dart b/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dart index a402037ff080..503129ef3c59 100644 --- a/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dart +++ b/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dart @@ -6,27 +6,24 @@ import 'package:flutter/material.dart'; -void main() => runApp(const MyApp()); +void main() => runApp(const BottomSheetApp()); -class MyApp extends StatelessWidget { - const MyApp({super.key}); - - static const String _title = 'Flutter Code Sample'; +class BottomSheetApp extends StatelessWidget { + const BottomSheetApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( - title: _title, home: Scaffold( - appBar: AppBar(title: const Text(_title)), - body: const MyStatelessWidget(), + appBar: AppBar(title: const Text('Bottom Sheet Sample')), + body: const BottomSheetExample(), ), ); } } -class MyStatelessWidget extends StatelessWidget { - const MyStatelessWidget({super.key}); +class BottomSheetExample extends StatelessWidget { + const BottomSheetExample({super.key}); @override Widget build(BuildContext context) { diff --git a/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.1.dart b/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.1.dart index 392094e33046..21eda9e8af01 100644 --- a/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.1.dart +++ b/examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.1.dart @@ -2,30 +2,32 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Flutter code sample for Material Design 3 TextFields. /// Flutter code sample for [showModalBottomSheet]. import 'package:flutter/material.dart'; -void main() => runApp(const MyApp()); +void main() => runApp(const BottomSheetApp()); -class MyApp extends StatelessWidget { - const MyApp({super.key}); +class BottomSheetApp extends StatelessWidget { + const BottomSheetApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( - theme: ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true), + theme: ThemeData( + colorSchemeSeed: const Color(0xff6750a4), + useMaterial3: true, + ), home: Scaffold( appBar: AppBar(title: const Text('Bottom Sheet Sample')), - body: const MyStatelessWidget(), + body: const BottomSheetExample(), ), ); } } -class MyStatelessWidget extends StatelessWidget { - const MyStatelessWidget({super.key}); +class BottomSheetExample extends StatelessWidget { + const BottomSheetExample({super.key}); @override Widget build(BuildContext context) { diff --git a/examples/api/test/material/bottom_sheet/show_modal_bottom_sheet.0_test.dart b/examples/api/test/material/bottom_sheet/show_modal_bottom_sheet.0_test.dart new file mode 100644 index 000000000000..7b5e1450760e --- /dev/null +++ b/examples/api/test/material/bottom_sheet/show_modal_bottom_sheet.0_test.dart @@ -0,0 +1,29 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_api_samples/material/bottom_sheet/show_modal_bottom_sheet.0.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('BottomSheet can be opened and closed', (WidgetTester tester) async { + const String titleText = 'Modal BottomSheet'; + const String closeText = 'Close BottomSheet'; + + await tester.pumpWidget( + const example.BottomSheetApp(), + ); + + expect(find.text(titleText), findsNothing); + expect(find.text(closeText), findsNothing); + + // Open the bottom sheet. + await tester.tap(find.widgetWithText(ElevatedButton, 'showModalBottomSheet')); + await tester.pumpAndSettle(); + + // Verify that the bottom sheet is open. + expect(find.text(titleText), findsOneWidget); + expect(find.text(closeText), findsOneWidget); + }); +} diff --git a/examples/api/test/material/bottom_sheet/show_modal_bottom_sheet.1_test.dart b/examples/api/test/material/bottom_sheet/show_modal_bottom_sheet.1_test.dart new file mode 100644 index 000000000000..3fc63af4f755 --- /dev/null +++ b/examples/api/test/material/bottom_sheet/show_modal_bottom_sheet.1_test.dart @@ -0,0 +1,29 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_api_samples/material/bottom_sheet/show_modal_bottom_sheet.1.dart' as example; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('BottomSheet can be opened and closed', (WidgetTester tester) async { + const String titleText = 'Modal BottomSheet'; + const String closeText = 'Close BottomSheet'; + + await tester.pumpWidget( + const example.BottomSheetApp(), + ); + + expect(find.text(titleText), findsNothing); + expect(find.text(closeText), findsNothing); + + // Open the bottom sheet. + await tester.tap(find.widgetWithText(ElevatedButton, 'showModalBottomSheet')); + await tester.pumpAndSettle(); + + // Verify that the bottom sheet is open. + expect(find.text(titleText), findsOneWidget); + expect(find.text(closeText), findsOneWidget); + }); +} diff --git a/packages/flutter/lib/src/material/bottom_sheet.dart b/packages/flutter/lib/src/material/bottom_sheet.dart index 11a9321fa957..e5995b7fe9c6 100644 --- a/packages/flutter/lib/src/material/bottom_sheet.dart +++ b/packages/flutter/lib/src/material/bottom_sheet.dart @@ -799,6 +799,13 @@ class _BottomSheetSuspendedCurve extends ParametricCurve { /// ** See code in examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.0.dart ** /// {@end-tool} /// +/// {@tool dartpad} +/// This sample shows the creation of [showModalBottomSheet], as described in: +/// https://m3.material.io/components/bottom-sheets/overview +/// +/// ** See code in examples/api/lib/material/bottom_sheet/show_modal_bottom_sheet.1.dart ** +/// {@end-tool} +/// /// See also: /// /// * [BottomSheet], which becomes the parent of the widget returned by the