Skip to content

[go_router_builder] fragment as a parameter #139387

@TekExplorer

Description

@TekExplorer

Is there an existing issue for this?

Use case

I would like to use go_router_builder for my app, but the problem i have right now is that i want to use the fragment instead of path or query parameters (ex for say, a file path)

The problem is, i dont see any way to define that without breaking the generator.

class ServerFileEditorRoute extends GoRouteData {
  ServerFileEditorRoute({
    required this.serverId,
    required this.filePath, // should be using the fragment, not query parameter.
  });
/* different issue
  ServerFileEditorRoute.typed({
    required this.serverId,
    required FileUri filePath,
  }) : filePath = filePath.fullPath;
*/
  final ServerId serverId;
  final String filePath;

  @override
  Widget build(BuildContext context, GoRouterState state) {
    return ServerFileEditorPage(
      key: state.pageKey,
      serverId: serverId,
      // TODO: pass in the path somehow
      // filePath: FileUri(state.uri.fragment), // might work, but then i cant specify it in the constructor
      filePath: FileUri(filePath),
    );
  }

  // ensures the fragment is valid, since i want to use it for the parameter
  @override
  FutureOr<String?> redirect(BuildContext context, GoRouterState state) async {
    if (!state.uri.hasFragment) {
      return '../';
    }
    return null;
  }
}

Proposal

Perhaps a $fragment the same way we have $extra?

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: go_router_builderThe go_router_builder packagepackageflutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions