Comments (9)
Hi!
Did you use Bindings when you call Get.toNamed(AppRoutes.home); on screen A? If you use bindings, pass you MainLogic controller in bindings like that
class HomeBindings extends Bindings {
@override
void dependencies() {
Get.put(MainLogic());
}
}
and pass your Binding in GetPage
or if you don't want use Binding
you need to call Get.put before use call Get.find
For example you can init your controller automatically with GetBuilder
class MainWidget extends GetView<MainLogic> {
const MainWidget({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Main"),
),
body: InkWell(
onTap: () {
controller.changeContent();
},
child: SizedBox(
width: double.infinity,
height: double.infinity,
child: Center(
child: GetBuilder<MainLogic>(
init: MainLogic(), //HERE!!
assignId: true,
builder: (logic) {
return Text(controller.content);
},
),
),
),
),
);
}
}
or you can call Get.put in build method before returning you widgets
class MainWidget extends GetView<MainLogic> {
const MainWidget({super.key});
@override
Widget build(BuildContext context) {
Get.put(MainLogic()); //HERE;
return Scaffold(
appBar: AppBar(
title: const Text("Main"),
),
body: // YOUR UI
);
}
}
from getx.
Yes, I used bindings, this is only possible if B quickly jumps to B again when B returns to A, other scenarios are normal.
class SplashBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut(() => SplashLogic());
}
}
class MainBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut(() => MainLogic());
}
}
class AppPages {
static const initial = AppRoutes.initial;
static final List<GetPage> getPages = [
GetPage(
name: AppRoutes.initial,
page: () => SplashWidget(),
binding: SplashBinding(),
),
GetPage(
name: AppRoutes.home,
page: () => MainWidget(),
binding: MainBinding(),
),
];
}
from getx.
Hello! Yes, I also caught an error, but in order to catch it, I need to very quickly press the button and return to screen B before Get has time to call onDispose.
If in your case you are supposed to press so quickly, then two options come to mind.
- Just block the button on the screen And if your controller has not yet been removed from memory. For example, when tapping, you can check for dependencies in memory
class SplashWidget extends GetView<SplashLogic> {
const SplashWidget({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Splash"),
),
body: InkWell(
onTap: () async {
try {
// Try to find your controller
final mainLogic = Get.find<MainLogic>();
// If it still in memory, do nothing
return;
} catch (e) {
// If it is not in memory, push your route
await Get.toNamed(AppRoutes.home);
}
},
child: const SizedBox(
width: double.infinity,
height: double.infinity,
child: Center(
child: Text("Go home"),
),
),
),
);
}
}
- There is an option not to delete the controller from memory.
class MainBinding extends Bindings {
@override
void dependencies() {
// Use permament `true` and Get will not remove your dependency from memory.
Get.put(MainLogic(), permanent: true);
}
}
from getx.
Um... After B returns to A, onDispose is called about 0.3~0.5s.
The first option requires an interception to be added before all page jumps;
The second option occupies memory all the time and is not very friendly.
Hope there's a better solution.
Such as reducing the latency of onDispose, or not removing onDispose when a new GetView is using controller.
from getx.
Quite a few users are seeing this error in apps that are currently in production.
Has this issue been fixed in GetX5?
from getx.
Quite a few users are seeing this error in apps that are currently in production. Has this issue been fixed in GetX5?
Hello! No, this bug was not fixed in Getx 5.0. But I got the impression that in Get 5.0 I still catch it less often than in v4.6.6
from getx.
Hi, you can try set binding parameter in Get.to(), that error comes when you set binding in bindings file only. And maybe you need to set 'preventDuplicates' to prevent not opening the widget with the same tree
Get.to(
() => widget,
preventDuplicates: false,
binding: BindingsBuilder.put(controller, tag: tag),
);
from getx.
Is it possible to check with isRegistered instead of catching the error with find?
from getx.
I have also encountered this problem. When I quickly enter and exit the page, this error will be caused. I try to modify the code by adding a mixin GetReferenceMixin to GetInstance. As long as GetBuilder is not released, GetxController will not be released.Reference code
from getx.
Related Issues (20)
- ChangeThemeMode Error UI.
- Controllers are getting disposed sometimes
- in example_nav2 logout from other page dashboard controller will create and init again
- onInit() of GetxController sometimes will not call.
- GetxService onInit in an error GetLifeCycle HOT 2
- Bug Hiding all children when using Stack() with Visibility() or IF (visibility) for a child HOT 4
- Call for Funding | Future for Production Usage HOT 8
- Troubleshooting Persistent Bottom Navigation Bar Issues with GetX in Flutter HOT 1
- Beware, on Flutter 3.24, the `onPopPage` is deprecated. HOT 5
- Compatibility Issue Between GetX 5.0.0-release-candidate-6 and share_plus 10.0.1 HOT 1
- Feature Request: Major Updates and Documentation Enhancement for GetX
- GetX 5 web refresh blank screen HOT 1
- GetX 5 `GetMiddleware` almost all functions like `onPageBuilt` run twice HOT 5
- Kindly support location_web web
- Getx will be release ? HOT 5
- Exception: GetRoot is not part of the three 【get: ^5.0.0-release-candidate-8】 HOT 3
- Why GetX 5 removed `offAllNamed` `predicate` HOT 6
- firebase_messaging_web issues : et >=5.0.0-release-candidate-8 depends on web ^1.0.0, get >=5.0.0-release-candidate-8 is incompatible with firebase_messaging_web ^3.8.12. HOT 4
- Getx Middleware is not properly working in getx-5 update HOT 1
- Get.until not working properly on getx 5 candidate 8 HOT 2
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.