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> {
/// 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._();
......@@ -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._();
......
......@@ -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);
......@@ -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);
......
......@@ -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),
),
......@@ -1710,8 +1710,8 @@ 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);
......@@ -1719,8 +1719,8 @@ void main() {
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>{
......
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