Unverified Commit e55aa0e8 authored by Tong Mu's avatar Tong Mu Committed by GitHub

Allow DoNothingIntent and DoNothingAndStopPropagationIntent to be used in a...

Allow DoNothingIntent and DoNothingAndStopPropagationIntent to be used in a const environment (#105983)
parent 92034482
...@@ -1342,7 +1342,7 @@ class VoidCallbackAction extends Action<VoidCallbackIntent> { ...@@ -1342,7 +1342,7 @@ class VoidCallbackAction extends Action<VoidCallbackIntent> {
/// handlers in the focus chain. /// handlers in the focus chain.
class DoNothingIntent extends Intent { class DoNothingIntent extends Intent {
/// Creates a const [DoNothingIntent]. /// Creates a const [DoNothingIntent].
factory DoNothingIntent() => const DoNothingIntent._(); const factory DoNothingIntent() = DoNothingIntent._;
// Make DoNothingIntent constructor private so it can't be subclassed. // Make DoNothingIntent constructor private so it can't be subclassed.
const DoNothingIntent._(); const DoNothingIntent._();
...@@ -1367,7 +1367,7 @@ class DoNothingIntent extends Intent { ...@@ -1367,7 +1367,7 @@ class DoNothingIntent extends Intent {
/// * [DoNothingIntent], a similar intent that will handle the key event. /// * [DoNothingIntent], a similar intent that will handle the key event.
class DoNothingAndStopPropagationIntent extends Intent { class DoNothingAndStopPropagationIntent extends Intent {
/// Creates a const [DoNothingAndStopPropagationIntent]. /// Creates a const [DoNothingAndStopPropagationIntent].
factory DoNothingAndStopPropagationIntent() => const DoNothingAndStopPropagationIntent._(); const factory DoNothingAndStopPropagationIntent() = DoNothingAndStopPropagationIntent._;
// Make DoNothingAndStopPropagationIntent constructor private so it can't be subclassed. // Make DoNothingAndStopPropagationIntent constructor private so it can't be subclassed.
const DoNothingAndStopPropagationIntent._(); const DoNothingAndStopPropagationIntent._();
......
...@@ -120,7 +120,7 @@ void main() { ...@@ -120,7 +120,7 @@ void main() {
await tester.pump(); await tester.pump();
final Object? result = Actions.maybeInvoke( final Object? result = Actions.maybeInvoke(
containerKey.currentContext!, containerKey.currentContext!,
DoNothingIntent(), const DoNothingIntent(),
); );
expect(result, isNull); expect(result, isNull);
expect(invoked, isFalse); expect(invoked, isFalse);
...@@ -146,7 +146,7 @@ void main() { ...@@ -146,7 +146,7 @@ void main() {
await tester.pump(); await tester.pump();
final Object? result = Actions.maybeInvoke( final Object? result = Actions.maybeInvoke(
containerKey.currentContext!, containerKey.currentContext!,
DoNothingIntent(), const DoNothingIntent(),
); );
expect(result, isNull); expect(result, isNull);
expect(invoked, isFalse); expect(invoked, isFalse);
......
...@@ -871,7 +871,7 @@ void main() { ...@@ -871,7 +871,7 @@ void main() {
}, },
child: Shortcuts( child: Shortcuts(
shortcuts: <LogicalKeySet, Intent>{ shortcuts: <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.keyA): DoNothingAndStopPropagationIntent(), LogicalKeySet(LogicalKeyboardKey.keyA): const DoNothingAndStopPropagationIntent(),
}, },
child: TextField(key: textFieldKey, autofocus: true), child: TextField(key: textFieldKey, autofocus: true),
), ),
...@@ -1710,8 +1710,8 @@ void main() { ...@@ -1710,8 +1710,8 @@ void main() {
testWidgets('using a disposed token asserts', (WidgetTester tester) async { testWidgets('using a disposed token asserts', (WidgetTester tester) async {
final ShortcutRegistry registry = ShortcutRegistry(); final ShortcutRegistry registry = ShortcutRegistry();
final ShortcutRegistryEntry token = registry.addAll(<ShortcutActivator, Intent>{ final ShortcutRegistryEntry token = registry.addAll(const <ShortcutActivator, Intent>{
const SingleActivator(LogicalKeyboardKey.keyA): DoNothingIntent(), SingleActivator(LogicalKeyboardKey.keyA): DoNothingIntent(),
}); });
token.dispose(); token.dispose();
expect(() {token.replaceAll(<ShortcutActivator, Intent>{}); }, throwsFlutterError); expect(() {token.replaceAll(<ShortcutActivator, Intent>{}); }, throwsFlutterError);
...@@ -1719,8 +1719,8 @@ void main() { ...@@ -1719,8 +1719,8 @@ void main() {
testWidgets('setting duplicate bindings asserts', (WidgetTester tester) async { testWidgets('setting duplicate bindings asserts', (WidgetTester tester) async {
final ShortcutRegistry registry = ShortcutRegistry(); final ShortcutRegistry registry = ShortcutRegistry();
final ShortcutRegistryEntry token = registry.addAll(<ShortcutActivator, Intent>{ final ShortcutRegistryEntry token = registry.addAll(const <ShortcutActivator, Intent>{
const SingleActivator(LogicalKeyboardKey.keyA): DoNothingIntent(), SingleActivator(LogicalKeyboardKey.keyA): DoNothingIntent(),
}); });
expect(() { expect(() {
final ShortcutRegistryEntry token2 = registry.addAll(const <ShortcutActivator, Intent>{ final ShortcutRegistryEntry token2 = registry.addAll(const <ShortcutActivator, Intent>{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment