diff --git a/packages/flutter/lib/src/widgets/actions.dart b/packages/flutter/lib/src/widgets/actions.dart index ef99513b92..962bd9769c 100644 --- a/packages/flutter/lib/src/widgets/actions.dart +++ b/packages/flutter/lib/src/widgets/actions.dart @@ -581,7 +581,13 @@ class Actions extends StatefulWidget { /// that are found. /// /// Setting `nullOk` to true means that if no ambient [Actions] widget is - /// found, then this method will return false instead of throwing. + /// found, then this method will return null instead of throwing. + /// + /// Returns the result of invoking the action's [Action.invoke] method. If + /// no action mapping was found for the specified intent, or if the action + /// that was found was disabled, then this returns null. Callers can detect + /// whether or not the action is available (found, and not disabled) using + /// [Actions.find] with its `nullOk` argument set to true. static Object invoke( BuildContext context, T intent, { @@ -624,7 +630,7 @@ class Actions extends StatefulWidget { }()); // Invoke the action we found using the relevant dispatcher from the Actions // Element we found. - return actionElement != null ? _findDispatcher(actionElement).invokeAction(action, intent, context) != null : null; + return actionElement != null ? _findDispatcher(actionElement).invokeAction(action, intent, context) : null; } @override diff --git a/packages/flutter/test/widgets/actions_test.dart b/packages/flutter/test/widgets/actions_test.dart index 7fa2ee2bf9..8e9b6474aa 100644 --- a/packages/flutter/test/widgets/actions_test.dart +++ b/packages/flutter/test/widgets/actions_test.dart @@ -423,6 +423,36 @@ void main() { expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.forbidden); }); + testWidgets('Actions.invoke returns the value of Action.invoke', (WidgetTester tester) async { + final GlobalKey containerKey = GlobalKey(); + final Object sentinel = Object(); + bool invoked = false; + const TestIntent intent = TestIntent(); + final Action testAction = TestAction( + onInvoke: (Intent intent) { + invoked = true; + return sentinel; + }, + ); + + await tester.pumpWidget( + Actions( + dispatcher: TestDispatcher(postInvoke: collect), + actions: >{ + TestIntent: testAction, + }, + child: Container(key: containerKey), + ), + ); + + await tester.pump(); + final Object result = Actions.invoke( + containerKey.currentContext, + intent, + ); + expect(identical(result, sentinel), isTrue); + expect(invoked, isTrue); + }); }); group('Listening', () { @@ -484,7 +514,7 @@ void main() { const TestIntent(), ); expect(enabled1, isFalse); - expect(result, isFalse); + expect(result, isNull); expect(invoked1, isFalse); action1.enabled = true; @@ -523,7 +553,7 @@ void main() { ); expect(enabledChanged, isNull); expect(enabled2, isFalse); - expect(result, isFalse); + expect(result, isNull); expect(invoked2, isFalse); action2.enabled = true;