mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
parent
322dd06d6e
commit
333397a0ed
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
@ -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);
|
||||
});
|
||||
}
|
@ -799,6 +799,13 @@ class _BottomSheetSuspendedCurve extends ParametricCurve<double> {
|
||||
/// ** 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
|
||||
|
Loading…
Reference in New Issue
Block a user