forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add MenuMenuAcceleratorLabel to support accelerators. * Review Changes * Review Changed * Fix default label builder to use characters * Remove golden test that shouldn't have been there.
- Loading branch information
1 parent
db631f1
commit 0cb9f70
Showing
9 changed files
with
1,592 additions
and
669 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
116 changes: 116 additions & 0 deletions
116
examples/api/lib/material/menu_anchor/menu_accelerator_label.0.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// 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. | ||
|
||
/// Flutter code sample for [MenuAcceleratorLabel]. | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
void main() => runApp(const MenuAcceleratorApp()); | ||
|
||
class MyMenuBar extends StatelessWidget { | ||
const MyMenuBar({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: <Widget>[ | ||
Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: <Widget>[ | ||
Expanded( | ||
child: MenuBar( | ||
children: <Widget>[ | ||
SubmenuButton( | ||
menuChildren: <Widget>[ | ||
MenuItemButton( | ||
onPressed: () { | ||
showAboutDialog( | ||
context: context, | ||
applicationName: 'MenuBar Sample', | ||
applicationVersion: '1.0.0', | ||
); | ||
}, | ||
child: const MenuAcceleratorLabel('&About'), | ||
), | ||
MenuItemButton( | ||
onPressed: () { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar( | ||
content: Text('Saved!'), | ||
), | ||
); | ||
}, | ||
child: const MenuAcceleratorLabel('&Save'), | ||
), | ||
MenuItemButton( | ||
onPressed: () { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar( | ||
content: Text('Quit!'), | ||
), | ||
); | ||
}, | ||
child: const MenuAcceleratorLabel('&Quit'), | ||
), | ||
], | ||
child: const MenuAcceleratorLabel('&File'), | ||
), | ||
SubmenuButton( | ||
menuChildren: <Widget>[ | ||
MenuItemButton( | ||
onPressed: () { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar( | ||
content: Text('Magnify!'), | ||
), | ||
); | ||
}, | ||
child: const MenuAcceleratorLabel('&Magnify'), | ||
), | ||
MenuItemButton( | ||
onPressed: () { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
const SnackBar( | ||
content: Text('Minify!'), | ||
), | ||
); | ||
}, | ||
child: const MenuAcceleratorLabel('Mi&nify'), | ||
), | ||
], | ||
child: const MenuAcceleratorLabel('&View'), | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
Expanded( | ||
child: FlutterLogo( | ||
size: MediaQuery.of(context).size.shortestSide * 0.5, | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} | ||
|
||
class MenuAcceleratorApp extends StatelessWidget { | ||
const MenuAcceleratorApp({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
home: Shortcuts( | ||
shortcuts: <ShortcutActivator, Intent>{ | ||
const SingleActivator(LogicalKeyboardKey.keyT, control: true): VoidCallbackIntent(() { | ||
debugDumpApp(); | ||
}), | ||
}, | ||
child: const Scaffold(body: MyMenuBar()), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
examples/api/test/material/menu_anchor/menu_accelerator_label.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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/services.dart'; | ||
import 'package:flutter_api_samples/material/menu_anchor/menu_accelerator_label.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Can open menu', (WidgetTester tester) async { | ||
Finder findMenu(String label) { | ||
return find | ||
.ancestor( | ||
of: find.text(label, findRichText: true), | ||
matching: find.byType(FocusScope), | ||
) | ||
.first; | ||
} | ||
|
||
await tester.pumpWidget(const example.MenuAcceleratorApp()); | ||
|
||
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft); | ||
await tester.pump(); | ||
await tester.sendKeyEvent(LogicalKeyboardKey.keyF, character: 'f'); | ||
await tester.pumpAndSettle(); | ||
await tester.pump(); | ||
|
||
expect(find.text('About', findRichText: true), findsOneWidget); | ||
expect( | ||
tester.getRect(findMenu('About')), | ||
equals(const Rect.fromLTRB(4.0, 48.0, 98.0, 208.0)), | ||
); | ||
expect(find.text('Save', findRichText: true), findsOneWidget); | ||
expect(find.text('Quit', findRichText: true), findsOneWidget); | ||
expect(find.text('Magnify', findRichText: true), findsNothing); | ||
expect(find.text('Minify', findRichText: true), findsNothing); | ||
|
||
// Open the About dialog. | ||
await tester.sendKeyEvent(LogicalKeyboardKey.keyA, character: 'a'); | ||
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text('Save', findRichText: true), findsNothing); | ||
expect(find.text('Quit', findRichText: true), findsNothing); | ||
expect(find.text('Magnify', findRichText: true), findsNothing); | ||
expect(find.text('Minify', findRichText: true), findsNothing); | ||
expect(find.text('CLOSE'), findsOneWidget); | ||
|
||
await tester.tap(find.text('CLOSE')); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('CLOSE'), findsNothing); | ||
}); | ||
} |
Oops, something went wrong.