-
Hello! I have an issue using a Drawer along with the go_router. My Question is: How to use the In this example the Drawer won't close when tapping the import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
void main() async {
runApp(MyApp());
}
final router = GoRouter(
routes: [
GoRoute(
path: '/',
builder: (context, state) => Text('Body'),
),
],
navigatorBuilder: (context, state, child) => Scaffold(
drawer: AppDrawer(),
body: child,
));
class MyApp extends StatefulWidget {
static BuildContext? navigationContext;
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
@override
Widget build(BuildContext context) {
return MaterialApp.router(
debugShowCheckedModeBanner: false,
routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
);
}
}
class AppDrawer extends StatelessWidget {
Widget build(BuildContext context) {
return Drawer(
backgroundColor: Theme.of(context).backgroundColor,
child: ListView(
padding: EdgeInsets.zero,
children: [
ListTile(
title: Text('Close me'),
onTap: () {
GoRouter.of(context).pop();
},
),
],
),
);
}
}
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I believe you'll be able to close your Drawer with a call to |
Beta Was this translation helpful? Give feedback.
-
Since your
This root navigator can handle dialogs, sheets, overlays as well. |
Beta Was this translation helpful? Give feedback.
Since your
AppDrawer
is actually above theNavigator
here, I think you probably need to wrap an outer navigator to handle it:This root navigator can handle dialogs, sheets, overlays as well.