Fix return type of ContextAction.invoke (#70397)
This commit is contained in:
committed by
GitHub
parent
5fedad9173
commit
c7f092515c
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user