Comments (11)
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.
from getx.
from getx.
It is not necessary to add Drawer to Get, because it uses the root browser, which in this case will be Get.
In the test case, Get.back (); had the same behavior as Navigator.pop (context);
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.
from getx.
This issue still not fixed.
When drawer closed, controller would be immediately deleted from memory.
from getx.
My get version is 3.21.3
from getx.
@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.
from getx.
When the drawer is closed, nothing should be removed from memory. Drawer is not a route.
from getx.
Please try with GetView.
Thank you
from getx.
I just fixed it temporary by putting with permanent option
from getx.
Any update?
Get.back
or Navigator.mayPop
all same behavior.
They are all cleaning controller from memory when drawer closed.
from getx.
Please try with GetView.
Thank you
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;
}
}
from getx.
Related Issues (20)
- Instance "GetLifeCycleBase?" is not registered.
- Drawer Menu disappear after changing app locale in drawer
- when I use Get.dialog() to show a dialog, then I use Get.back() back dialog, at the same time ,the page widget's getxController operator onClose(), how to solve this problem. HOT 3
- Get.dilog().adaptive()
- Create a Getx organization HOT 3
- GetX update. HOT 2
- hello please add material design 3 to this package , thank for persue. HOT 1
- [GETX] "AddWorkerController" deleted from memory but actually not deleted HOT 1
- Displaying a Snackbar that is does not use the full width makes buttons on that height unclickable.
- [Flutter 3.16.5][GetX-5_RC5] PopScope issue HOT 12
- Error: Undefined name 'required'.
- Memory leaks HOT 1
- Can get.to specify context? HOT 1
- RxList in Getx bindStream, but Obx keep get old data emmited
- Nested GetRouterOutlet not working as expected HOT 2
- UI Not Updating with Switch/Toggle in ListView using GetX Controller
- Back button in browser don't behave the same as Get.back()
- Reactive variable observation issues HOT 2
- 是否可以在 GetMiddleware 中拿到正确的 arguments 值
- The GetxController is not automatically deleted if it is the first child of GetMaterialApp HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from getx.