Skip to content

Actions.find et.al should return Action<Intent> instead of Action<T>. #180871

Open

Description

@LongCatIsLooong

This is a TODO extracted from #180435.

In the Action<T extends Intent> class the type parameter T is contravariant since an instance of Action<Intent> should be able to handle any Intent. But currently it means the opposite: an Action<Intent> can handle Intent, but not any Intent subtypes. This is a problem for find but not invoke.

expected behavior:

final class MyIntent extends Intent {}

// Put this widget in the tree.
Actions(
  actions: const {
    MyIntent: DoNothingAction(),
  },
  child: ...
),

// Able to find the intent 
final intent = Actions.find<Intent>(context, intent: intent);

Actual behavior:
crashes because currently Actions.find returns Action<T>. We are able to find Action<U> where T :< U (and verify that in debug mode), but casting the Action<U> to Action<T> would result in a runtime crash.

Options:

  1. ignore this and wait for contravariance to be added
  2. change the return type to Action<Intent>
  3. deprecate maybeFind and find and redirect people to invoke.

Activity

  1. added
    in triagePresently being triaged by the triage team
    c: new featureNothing broken; request for a new capability
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: proposalA detailed proposal for a change to Flutter
    p: material_uimaterial_ui package in flutter/packages
    and removed
    in triagePresently being triaged by the triage team
    on Jan 13, 2026
  2. loic-sharma commented on Jan 13, 2026

    @loic-sharma
    Member

    @LongCatIsLooong would another option be to deprecate maybeFind and find in favor of new methods with return type Action<Intent>?

    Potential names for the new methods:

    • Actions.of, maybe acceptable since this does establish a dependency
    • Actions.lookup
    • Actions.get
  3. added
    packageflutter/packages repository. See also p: labels.
    and removed
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: material_uimaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.team-text-inputOwned by Text Input teamtriaged-text-inputTriaged by Text Input team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions