Skip to content

[go_router_builder] Support Enhanced enums #105876

Closed
flutter/packages
#2395

Description

@riscait

Steps to Reproduce

  1. Defines the Enhanced-enum that is now available in Dart 2.17.
enum Fruit {
  apple(themeColor: Colors.red),
  banana(themeColor: Colors.yellow),
  orange(themeColor: Colors.orange),
  ;

  const Fruit({required this.themeColor});

  final Color themeColor;
}
  1. Define a TypedGoRoute that takes Fruit as an argument.
@TypedGoRoute<FruitRoute>(
  path: '/:fruit',
)
class FruitRoute extends GoRouteData {
  const FruitRoute({required this.fruit});

  final Fruit fruit;

  @override
  Widget build(BuildContext context) => const FruitPage();
}
  1. Perform code generation. flutter pub run build_runner build
  2. Build the application.
  3. An error is displayed in the console and the build fails.
: Error: Member not found: 'themeColor'.
lib/…/router/app_routes.g.dart:204
  Fruit.themeColor: 'theme-color',
        ^^^^^^^^^^

It seems that go_router_builder also recognizes Enhanced-enum fields (themeColor in the example) as an value of Enum.

Both go_router_builder and Enhanced-enum are great features and should be used together.

I will add any missing information.

Thank you!

Activity

  1. danagbemava-nc commented on Jun 13, 2022

    @danagbemava-nc
    Member

    I see some errors when I generate the code with the enhanced enums.
    Leaving this for further input from the team.

    flutter analyze
      error • The method '_$fromName' isn't defined for the type 'Map' • lib/fruit_route.g.dart:20:31 • undefined_method
      error • Const variables must be initialized with a constant value • lib/fruit_route.g.dart:36:3 •
             const_initialized_with_non_constant_value
      error • The keys in a const map literal must be constant • lib/fruit_route.g.dart:36:3 • non_constant_map_key
      error • Instance member 'themeColor' can't be accessed using static access • lib/fruit_route.g.dart:36:9 •
             static_access_to_instance_member
       info • The declaration '_$fromName' isn't referenced • lib/fruit_route.g.dart:40:5 • unused_element
    

    Labeling as a proposal as this doesn't seem to be currently supported.

    Project for easy repro

    egrb.zip

  2. added
    c: new featureNothing broken; request for a new capability
    packageflutter/packages repository. See also p: labels.
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Jun 13, 2022
  3. added
    P3Issues that are less important to the Flutter project
    on Jun 14, 2022
  4. github-actions commented on Oct 3, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  5. locked as resolved and limited conversation to collaborators on Oct 3, 2022
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

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: go_router_builderThe go_router_builder packagepackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions