getx
getx copied to clipboard
Get.put objects lost if Get.off[Named] called
Describe the bug
Get.find
crashes if navigation is done with Get.off
or Get.offNamed`
Reproduction code
class SplashController extends BaseController {
final IAuthRepository _authRepository = Get.find();
AuthState get state => Get.find();
@override
Future<void> onReady() {
super.onReady();
Get.lazyPut(() => AuthState());
_getProfile();
}
void _getProfile() async {
final profile = await _authRepository.getUserProfile();
Get.offNamed(MainTabsScreen.routeName);
}
}
class OtherController {
AuthState get state => Get.find();
}
To Reproduce
- In the first controller put the state
Get.put
orGet.putAsync
- Call
Get.off
orGet.offNamed
to navigate to the second controller - Call
Get.find
with the type from the first controller
Expected behavior
Get.find<Type>()
finds objects normally
Actual behavior
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: "AuthState" not found. You need to call "Get.put(AuthState())" or "Get.lazyPut(()=>AuthState())"
#0 GetInstance.find (package:get/get_instance/src/get_instance.dart:305:7)
#1 Inst.find (package:get/get_instance/src/extension_instance.dart:69:45)
#2 SplashController.state (package:baitech_flutter/app/screens/splash/splash_controller.dart:14:30)
#3 SplashController._getProfile (package:baitech_flutter/app/screens/splash/splash_controller.dart:33:5)
#4 SplashController.onReady (package:baitech_flutter/app/screens/splash/splash_controller.dart:19:11)
#5 DisposableInterface.onInit.<anonymous closure> (package:get/get_state_manager/src/rx_flutter/rx_disposable.dart:21:44)
#6 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1145:15)
#7 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1090:9)
#8 SchedulerBinding._handleDrawFrame (package:flutter/src/<…>
Flutter Version: 2.8.1
Getx Version: 4.6.5
Describe on which device you found the bug: iPhone 12 mini simulator
same
same