Skip to content

Commit e55aa0e

Browse files
authored
Allow DoNothingIntent and DoNothingAndStopPropagationIntent to be used in a const environment (#105983)
1 parent 9203448 commit e55aa0e

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

packages/flutter/lib/src/widgets/actions.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ class VoidCallbackAction extends Action<VoidCallbackIntent> {
13421342
/// handlers in the focus chain.
13431343
class DoNothingIntent extends Intent {
13441344
/// Creates a const [DoNothingIntent].
1345-
factory DoNothingIntent() => const DoNothingIntent._();
1345+
const factory DoNothingIntent() = DoNothingIntent._;
13461346

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

13721372
// Make DoNothingAndStopPropagationIntent constructor private so it can't be subclassed.
13731373
const DoNothingAndStopPropagationIntent._();

packages/flutter/test/widgets/actions_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void main() {
120120
await tester.pump();
121121
final Object? result = Actions.maybeInvoke(
122122
containerKey.currentContext!,
123-
DoNothingIntent(),
123+
const DoNothingIntent(),
124124
);
125125
expect(result, isNull);
126126
expect(invoked, isFalse);
@@ -146,7 +146,7 @@ void main() {
146146
await tester.pump();
147147
final Object? result = Actions.maybeInvoke(
148148
containerKey.currentContext!,
149-
DoNothingIntent(),
149+
const DoNothingIntent(),
150150
);
151151
expect(result, isNull);
152152
expect(invoked, isFalse);

packages/flutter/test/widgets/shortcuts_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ void main() {
871871
},
872872
child: Shortcuts(
873873
shortcuts: <LogicalKeySet, Intent>{
874-
LogicalKeySet(LogicalKeyboardKey.keyA): DoNothingAndStopPropagationIntent(),
874+
LogicalKeySet(LogicalKeyboardKey.keyA): const DoNothingAndStopPropagationIntent(),
875875
},
876876
child: TextField(key: textFieldKey, autofocus: true),
877877
),
@@ -1710,17 +1710,17 @@ void main() {
17101710

17111711
testWidgets('using a disposed token asserts', (WidgetTester tester) async {
17121712
final ShortcutRegistry registry = ShortcutRegistry();
1713-
final ShortcutRegistryEntry token = registry.addAll(<ShortcutActivator, Intent>{
1714-
const SingleActivator(LogicalKeyboardKey.keyA): DoNothingIntent(),
1713+
final ShortcutRegistryEntry token = registry.addAll(const <ShortcutActivator, Intent>{
1714+
SingleActivator(LogicalKeyboardKey.keyA): DoNothingIntent(),
17151715
});
17161716
token.dispose();
17171717
expect(() {token.replaceAll(<ShortcutActivator, Intent>{}); }, throwsFlutterError);
17181718
});
17191719

17201720
testWidgets('setting duplicate bindings asserts', (WidgetTester tester) async {
17211721
final ShortcutRegistry registry = ShortcutRegistry();
1722-
final ShortcutRegistryEntry token = registry.addAll(<ShortcutActivator, Intent>{
1723-
const SingleActivator(LogicalKeyboardKey.keyA): DoNothingIntent(),
1722+
final ShortcutRegistryEntry token = registry.addAll(const <ShortcutActivator, Intent>{
1723+
SingleActivator(LogicalKeyboardKey.keyA): DoNothingIntent(),
17241724
});
17251725
expect(() {
17261726
final ShortcutRegistryEntry token2 = registry.addAll(const <ShortcutActivator, Intent>{

0 commit comments

Comments
 (0)