Update MenuAnchor API examples (#156404)

## Description

Cleanup MenuAnchor API examples:
- Remove usage of useMaterial3
- fix some formatting issues
This commit is contained in:
Bruno Leroux 2024-10-08 21:15:07 +02:00 committed by GitHub
parent 34457fe1f5
commit 480869afe7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 10 additions and 14 deletions

View File

@ -101,9 +101,8 @@ class MenuApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const Scaffold(body: SafeArea(child: MyCheckboxMenu(message: kMessage))),
return const MaterialApp(
home: Scaffold(body: SafeArea(child: MyCheckboxMenu(message: kMessage))),
);
}
}

View File

@ -103,7 +103,6 @@ class MenuAcceleratorApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: Shortcuts(
shortcuts: <ShortcutActivator, Intent>{
const SingleActivator(LogicalKeyboardKey.keyT, control: true): VoidCallbackIntent(() {

View File

@ -202,9 +202,8 @@ class MenuApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const Scaffold(body: SafeArea(child: MyCascadingMenu(message: kMessage))),
return const MaterialApp(
home: Scaffold(body: SafeArea(child: MyCascadingMenu(message: kMessage))),
);
}
}

View File

@ -6,7 +6,6 @@ import 'package:flutter/material.dart';
/// Flutter code sample for [MenuAnchor].
void main() => runApp(const MenuAnchorApp());
// This is the type used by the menu below.
@ -17,9 +16,8 @@ class MenuAnchorApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const MenuAnchorExample(),
return const MaterialApp(
home: MenuAnchorExample(),
);
}
}
@ -43,8 +41,7 @@ class _MenuAnchorExampleState extends State<MenuAnchorExample> {
),
body: Center(
child: MenuAnchor(
builder:
(BuildContext context, MenuController controller, Widget? child) {
builder: (BuildContext context, MenuController controller, Widget? child) {
return IconButton(
onPressed: () {
if (controller.isOpen) {
@ -55,7 +52,8 @@ class _MenuAnchorExampleState extends State<MenuAnchorExample> {
},
icon: const Icon(Icons.more_horiz),
tooltip: 'Show menu',
);},
);
},
menuChildren: List<MenuItemButton>.generate(
3,
(int index) => MenuItemButton(

View File

@ -51,6 +51,7 @@ void main() {
expect(find.text(example.MenuBarApp.kMessage), findsOneWidget);
expect(find.text('Last Selected: Show Message'), findsOneWidget);
});
testWidgets('Shortcuts work', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MenuBarApp(),