-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scaffold's drawer opening is not added to navigation stack #24
Comments
Flutter creates a GlobalKey navigation for Drawers, another for snackbars, another for dialogs, another for bottomsheets, and accesses each one through the context. 'Get' goes contrary to this, and to save memory, put it all together in a single globalKey, instead of having one for each thing (since the documentation itself explains that globalKeys are expensive and should be avoided, but navigation unlike Framework that is incredible, falls short in several aspects). Drawer is not part of Get yet, so I have two options: add it to the package (I'm very busy, I wouldn't be able to do it in less than 1 month) or add the context as an option for to/back, to do as in the main navigation, navigate through the Navigator widget, passing the context than GlobalKey is using. |
No need to rush it, I can definitely wait for a proper implementation of
drawer, thanks.
Le sam. 21 mars 2020 à 22:54, Jonny Borges <notifications@github.com> a
écrit :
… Flutter creates a GlobalKey navigation for Drawers, another for snackbars,
another for dialogs, another for bottomsheets, and accesses each one
through the context. 'Get' goes contrary to this, and to save memory, put
it all together in a single globalKey, instead of having one for each thing
(since the documentation itself explains that globalKeys are expensive and
should be avoided, but navigation unlike Framework that is incredible,
falls short in several aspects). Drawer is not part of Get yet, so I have
two options: add it to the package (I'm very busy, I wouldn't be able to do
it in less than 1 month) or add the context as an option for to/back, to do
as in the main navigation, navigate through the Navigator widget, passing
the context than GlobalKey is using.
This looks ugly hack, but if it is a problem for you to wait, let me know
I can do it in minutes.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#24 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALTVXE7UKGTK7FS4SJESOR3RIUZTFANCNFSM4LQ2SPYA>
.
|
It is not necessary to add Drawer to Get, because it uses the root browser, which in this case will be Get. void main() {
runApp(MaterialApp(
home:MyHomePage(),
navigatorKey: Get.key,
navigatorObservers: [
GetObserver(),
],
));
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("test")),
body: Center(child: Text('My Page!')),
drawer: Drawer(
// Add a ListView to the drawer. This ensures the user can scroll
// through the options in the drawer if there isn't enough vertical
// space to fit everything.
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
title: Text('Item 1'),
onTap: () {
// Update the state of the app
// ...
// Then close the drawer
//Navigator.pop(context);
// Get.back();
},
),
ListTile(
title: Text('Item 2'),
onTap: () {
// Update the state of the app
// ...
// Then close the drawer
Get.back();
// Navigator.pop(context);
},
),
],
),
),
);
}
} So, closing this. |
This issue still not fixed. |
My get version is 3.21.3 |
@zl910627, I did a test and the controller is not removed from memory when the drawer is closed. Create a new issue and place a sample code that shows this behavior. |
When the drawer is closed, nothing should be removed from memory. Drawer is not a route. |
Please try with GetView. |
I just fixed it temporary by putting with permanent option |
Any update? |
I tested with GetView and the controller is not removed from memory, see an example below: import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() {
Get.put(HomeController());
runApp(GetMaterialApp(
initialRoute: '/home',
getPages: [
GetPage(
name: '/home',
page: () => MyHomePage(),
),
],
));
}
class MyHomePage extends GetView<HomeController> {
MyHomePage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("test")),
body: Center(child: Obx(() => Text('Count ${controller.count}'))),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
title: Text('Item 1'),
onTap: () {
controller.increment();
Get.back();
},
),
ListTile(
title: Text('Item 2'),
onTap: () {
controller.increment();
Get.back();
},
),
],
),
),
);
}
}
class HomeController extends GetxController {
final _count = 0.obs;
int get count => _count.value;
void increment() {
_count.value += 1;
}
} |
I don't know if this is intended, but opening a Scaffold's drawer doesn't add to the navigation stack, while Flutter default navigation does.
The text was updated successfully, but these errors were encountered: