[go: nahoru, domu]

Skip to content

Commit

Permalink
Fix Material 3 BottomSheet example (flutter#116112)
Browse files Browse the repository at this point in the history
fix title
  • Loading branch information
TahaTesser authored and shogohida committed Dec 7, 2022
1 parent 8a1be9f commit d7e2680
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
}
Original file line number Diff line number Diff line change
@@ -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);
});
}
7 changes: 7 additions & 0 deletions packages/flutter/lib/src/material/bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d7e2680

Please sign in to comment.