-
-
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
getxController isn't being disposed/deleted when it should be #961
Comments
change: Prime()
{
Get.put(PrimeController());
}
@override
Widget build(BuildContext context) { to: @override
Widget build(BuildContext context) {
Get.put(PrimeController()); The class constructor is called before the route, so it is attached to the previous route. |
@jasonlaw so, instead of adding the put inside the constructor i should add it to the build? |
same here! |
Apparently the initial route is being appended to '/', however you are not using named routes. I'm doing a hotfix now for this |
Had similar problem, for now you can use binding, everything works fine with that. |
binding sounds like a lot of work that's why i didn't use it in the first place, and this also means either A. i will do this only for the current issue i have in the given screen only making an inconsistency with my whole codebase or B. change my whole codebase to use bindings instead of the current method. but regardless of my preference i may have to resort to B because i won't ever know when i will encounter this issue again and it may go under the radar. sorry for the long rant. |
@xEyad take a look at BindingsBuilder, very easy to use Get.to(MyPage(), binding: BindingsBuilder(() {
Get.put<GController>(GController());
}),
); |
is the bug fixed ? |
I fix this bug with defining controller after build context, thanks all
…On Sun, Jan 3, 2021, 3:18 PM F-BONAPARTA ***@***.***> wrote:
is the bug fixed ?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#961 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKXWV4A2GHQT574LFULW4C3SYBKQHANCNFSM4VNULOVA>
.
|
nope
|
could you please share your code? |
I have the exact same issue with Timers.. even if GetX logs says the screen is fully deleted in memory, still the timer is still alive and kicking |
With FlatButton(
onPressed: () {
Get.to(() => DummyView(), binding: BindingsBuilder(() {
Get.put<DummyController>(DummyController());
}));
},
child: const Text(
'Dummy view',
),
), class DummyController extends GetxController {
final RxInt counter = 0.obs;
void increment() {
counter.value++;
}
@override
void onInit() {
logger.w('Dummy controller launched, counter value : $counter');
super.onInit();
}
} class DummyView extends GetView<DummyController> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
children: [
Obx(
() => Text('Counter value : ${controller.counter.value.toString()}'),
),
RaisedButton(
onPressed: () {
controller.increment();
},
child: const Text('Increment counter'),
)
],
),
),
),
);
}
} The controller is not deleted from memory if I use Get.to(() => DummyView(), id: 1, binding: BindingsBuilder(() {
Get.put<DummyController>(DummyController());
})); Same problem with named routes |
@zzterrozz, Why are you using |
We have the same use case as @zzterrozz. We use nested navigation in our app, and it seems like no Controllers are ever deleted. |
any updates on this bug |
From our experience a controller is never disposed when using
disposes the controller correctly in our cases. |
Same here. Any updates?? |
The problem I mentioned earlier may also be related to this |
Any update about this issue? |
Hello, im using Nested navigators, and i can't have a controller automatically disposed when navigating by id, even with a binding associated with it. Im forced to use From your documentation:
That's why this is an issue, we cannot use efficients solution using nested navigation |
I'm experiencing a similar issue, if I "Get.offAll" from the first screen, the controller never disposes, any news about this issue? |
Same issue, Getx controller is deleted every time when running app on emulator but after generating Apk , it does not delete controller from memory, hence causing the page to stuck to it's first view when the app begins. |
same issue , getx controller doesnt disposed when i changed page. |
I find solution for my problem |
This is my first time using a filter, this is really annoying. |
same issue here using nested navigation, the controller from generated nested routes are not being disposed. Also, the Getx nested navigation docs is poor... |
This is still an issue, is there any fix available other than using GetBuilder or GetX? Bindings are really annoying to deal with, I wouldn't even mind if I had to extend some other class instead of StatefulWidget but without using bindings. |
Please check this link https://stackoverflow.com/questions/73225356/what-is-the-best-way-to-dispose-resources-in-getx-flutter. |
Please check this link . https://stackoverflow.com/questions/73225356/what-is-the-best-way-to-dispose-resources-in-getx-flutter |
define binding class in diffrent files.not use common file for define binding |
If you are using statefull widget , here is a quick get around
|
Noticed, that on pressing physical back button (or back button in appbar) onClose is not called until i do some actions on previous screen. |
Try update Getx to 4.6.6. It solved like a magic in my case. |
Useful for me ❤ |
Solved this by using |
same |
I was dealing with this issue, which confused me because I had just been using Getx successfully in another app. After comparing all of my code differences, this is what I found, and changing it fixed things for me: In my broken app, I had changed routes: {
HomePage.ROUTE: (context) => const HomePage(),
HostPage.ROUTE: (context) => const HostPage(),
ClientPage.ROUTE: (context) => const ClientPage()
}, I changed this to use getPages: [
GetPage(name: HomePage.ROUTE, page: () => const HomePage()),
GetPage(name: HostPage.ROUTE, page: () => const HostPage()),
GetPage(name: ClientPage.ROUTE, page: () => const ClientPage()),
] And the issue was immediately resolved. Controllers are now being disposed/deleted. |
Describe the bug
when i go from screen 1 to screen 2 i expect the controller to be deleted/disposed but this doesn't happen. and you can see this as the timer completes from where it stopped.
i based my expectations on this document https://github.com/jonataslaw/getx/blob/master/documentation/en_US/state_management.md#simple-state-manager section How it handles controllers
Reproduction code
To Reproduce
Steps to reproduce the behavior:
Expected behavior
the timer should reset as the controller was disposed and rebuilt
Screenshots
none
Flutter Version:
1.22.5 stable channel
Getx Version:
get: ^3.22.2
Describe on which device you found the bug:
pixel api 28 5 inch - Android.
Minimal reproduce code
same as above
The text was updated successfully, but these errors were encountered: