Unverified Commit c7f09251 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Fix return type of ContextAction.invoke (#70397)

parent 5fedad91
......@@ -342,7 +342,7 @@ abstract class ContextAction<T extends Intent> extends Action<T> {
/// ```
@protected
@override
Object invoke(covariant T intent, [BuildContext? context]);
Object? invoke(covariant T intent, [BuildContext? context]);
}
/// The signature of a callback accepted by [CallbackAction].
......
......@@ -448,6 +448,33 @@ void main() {
expect(identical(result, sentinel), isTrue);
expect(invoked, isTrue);
});
testWidgets('ContextAction can return null', (WidgetTester tester) async {
final GlobalKey containerKey = GlobalKey();
const TestIntent intent = TestIntent();
final TestContextAction testAction = TestContextAction();
await tester.pumpWidget(
Actions(
dispatcher: TestDispatcher1(postInvoke: collect),
actions: <Type, Action<Intent>>{
TestIntent: testAction,
},
child: Container(key: containerKey),
),
);
await tester.pump();
final Object? result = Actions.invoke<TestIntent>(
containerKey.currentContext!,
intent,
);
expect(result, isNull);
expect(invokedIntent, equals(intent));
expect(invokedAction, equals(testAction));
expect(invokedDispatcher.runtimeType, equals(TestDispatcher1));
expect(testAction.capturedContexts.single, containerKey.currentContext);
});
});
group('Listening', () {
......@@ -834,3 +861,13 @@ void main() {
});
});
}
class TestContextAction extends ContextAction<TestIntent> {
List<BuildContext?> capturedContexts = <BuildContext?>[];
@override
Object? invoke(covariant TestIntent intent, [BuildContext? context]) {
capturedContexts.add(context);
return null;
}
}
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