3

I'm trying to open a page with OpenContainer, and passing the RouteSettings with name.

Is there any way to update the router.location from go_router package?

That's how I use OpenContainer, which OpenBuilder returns the page that I'm passing.

class _OpenContainerWrapper extends StatelessWidget {
  const _OpenContainerWrapper({
    required this.closedBuilder,
    required this.transitionType,
    required this.onClosed,
    required this.page,
    this.routeSettings,
    this.borderRadius = 4,
  });

  final CloseContainerBuilder closedBuilder;
  final ContainerTransitionType transitionType;
  final ClosedCallback<bool?> onClosed;
  final Widget page;
  final RouteSettings? routeSettings;
  final double borderRadius;

  @override
  Widget build(BuildContext context) {
    return OpenContainer<bool>(
      closedElevation: 0,
      closedColor: Colors.transparent,
      middleColor: Colors.transparent,
      openColor: Colors.transparent,
      routeSettings: routeSettings,
      closedShape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(
          Radius.circular(borderRadius),
        ),
      ),
      transitionType: transitionType,
      openBuilder: (BuildContext context, VoidCallback _) {
        return page;
      },
      onClosed: onClosed,
      tappable: false,
      closedBuilder: closedBuilder,
    );
  }
}

And that's how I'm using that wrapper as a button to open page that I'm passing.

return _OpenContainerWrapper(
      routeSettings: const RouteSettings(
        name: 'categories',
      ),
      page: const CategoryPage(),
      transitionType: ContainerTransitionType.fade,
      onClosed: (_) {},
      closedBuilder: (_, func) {
        return WidgetWithBackground(
          onTap: func,
          backgroundColor: textColor.withOpacity(
            0.25,
          ),
// More UI Code here relevant to the button.

This might be relevant: https://github.com/flutter/flutter/issues/51399

mirkancal
  • 4,762
  • 7
  • 37
  • 75

0 Answers0