Skip to content
This repository was archived by the owner on Feb 25, 2022. It is now read-only.
This repository was archived by the owner on Feb 25, 2022. It is now read-only.

Breadcrumbs and Cupertino Back Context Menu #260

@jamesblasco

Description

@jamesblasco

It would be great if we could make publicly accessible the current list of routes in the stack so it is possible to create Breadcrumbs and Cupertino Back Context Menu. The design of those components don't need to be part of this library, but it would be great if it makes it possible

RPReplay_Final1640194363.MP4
Simulator.Screen.Recording.-.iPhone.13.-.2021-12-22.at.18.33.38.mp4

Current approach

class BackButton extends StatelessWidget {
  const BackButton({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    assert(debugCheckHasMaterialLocalizations(context));

    return GestureDetector(
      onLongPress: () async {
        final router = GoRouter.of(context);
        final navigator = Navigator.of(context);
        if (router.routerDelegate.matches.isEmpty) return;
        final location = await showMenu(
            context: context,
            position: const RelativeRect.fromLTRB(0, 0, 20, 20),
            items: <PopupMenuEntry<String>>[
              for (final match
                  in router.routerDelegate.matches.reversed.skip(1))
                PopupMenuItem<String>(
                  value: match.route.name,
                  child: Text(match.route.name ?? 'Hey'),
                ),
            ]);
        if (location != null) {
          navigator.popUntil((route) => route.settings.name == location);
        }
      },
      child: IconButton(
        icon: const BackButtonIcon(),
        onPressed: () {
          Navigator.maybePop(context);
        },
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions