Fix return type of ContextAction.invoke (#70397)

This commit is contained in:
Michael Goderbauer
2020-11-12 13:54:03 -08:00
committed by GitHub
parent 5fedad9173
commit c7f092515c
2 changed files with 38 additions and 1 deletions

View File

@@ -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].

View File

@@ -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;
}
}