getx icon indicating copy to clipboard operation
getx copied to clipboard

Get.put objects lost if Get.off[Named] called

Open mancj opened this issue 2 years ago • 1 comments

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

  1. In the first controller put the state Get.put or Get.putAsync
  2. Call Get.off or Get.offNamed to navigate to the second controller
  3. 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

mancj avatar Jun 19 '22 18:06 mancj

same

melcurve avatar Aug 24 '22 15:08 melcurve

same

mxlt02 avatar Nov 16 '22 12:11 mxlt02