Skip to content

Commit

Permalink
Allow DoNothingIntent and DoNothingAndStopPropagationIntent to be use…
Browse files Browse the repository at this point in the history
…d in a const environment (#105983)
  • Loading branch information
dkwingsmt authored Jun 15, 2022
1 parent 9203448 commit e55aa0e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/widgets/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ class VoidCallbackAction extends Action<VoidCallbackIntent> {
/// handlers in the focus chain.
class DoNothingIntent extends Intent {
/// Creates a const [DoNothingIntent].
factory DoNothingIntent() => const DoNothingIntent._();
const factory DoNothingIntent() = DoNothingIntent._;

// Make DoNothingIntent constructor private so it can't be subclassed.
const DoNothingIntent._();
Expand All @@ -1367,7 +1367,7 @@ class DoNothingIntent extends Intent {
/// * [DoNothingIntent], a similar intent that will handle the key event.
class DoNothingAndStopPropagationIntent extends Intent {
/// Creates a const [DoNothingAndStopPropagationIntent].
factory DoNothingAndStopPropagationIntent() => const DoNothingAndStopPropagationIntent._();
const factory DoNothingAndStopPropagationIntent() = DoNothingAndStopPropagationIntent._;

// Make DoNothingAndStopPropagationIntent constructor private so it can't be subclassed.
const DoNothingAndStopPropagationIntent._();
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/test/widgets/actions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void main() {
await tester.pump();
final Object? result = Actions.maybeInvoke(
containerKey.currentContext!,
DoNothingIntent(),
const DoNothingIntent(),
);
expect(result, isNull);
expect(invoked, isFalse);
Expand All @@ -146,7 +146,7 @@ void main() {
await tester.pump();
final Object? result = Actions.maybeInvoke(
containerKey.currentContext!,
DoNothingIntent(),
const DoNothingIntent(),
);
expect(result, isNull);
expect(invoked, isFalse);
Expand Down
10 changes: 5 additions & 5 deletions packages/flutter/test/widgets/shortcuts_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ void main() {
},
child: Shortcuts(
shortcuts: <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.keyA): DoNothingAndStopPropagationIntent(),
LogicalKeySet(LogicalKeyboardKey.keyA): const DoNothingAndStopPropagationIntent(),
},
child: TextField(key: textFieldKey, autofocus: true),
),
Expand Down Expand Up @@ -1710,17 +1710,17 @@ void main() {

testWidgets('using a disposed token asserts', (WidgetTester tester) async {
final ShortcutRegistry registry = ShortcutRegistry();
final ShortcutRegistryEntry token = registry.addAll(<ShortcutActivator, Intent>{
const SingleActivator(LogicalKeyboardKey.keyA): DoNothingIntent(),
final ShortcutRegistryEntry token = registry.addAll(const <ShortcutActivator, Intent>{
SingleActivator(LogicalKeyboardKey.keyA): DoNothingIntent(),
});
token.dispose();
expect(() {token.replaceAll(<ShortcutActivator, Intent>{}); }, throwsFlutterError);
});

testWidgets('setting duplicate bindings asserts', (WidgetTester tester) async {
final ShortcutRegistry registry = ShortcutRegistry();
final ShortcutRegistryEntry token = registry.addAll(<ShortcutActivator, Intent>{
const SingleActivator(LogicalKeyboardKey.keyA): DoNothingIntent(),
final ShortcutRegistryEntry token = registry.addAll(const <ShortcutActivator, Intent>{
SingleActivator(LogicalKeyboardKey.keyA): DoNothingIntent(),
});
expect(() {
final ShortcutRegistryEntry token2 = registry.addAll(const <ShortcutActivator, Intent>{
Expand Down

0 comments on commit e55aa0e

Please sign in to comment.