[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Material 3 BottomSheet example #116112

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix Material 3 BottomSheet example
fix title
  • Loading branch information
TahaTesser committed Nov 28, 2022
commit cb0035ab08b76935adf859b09919d225eedebf91
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