jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.34k stars 1.62k forks source link

GetxControllers are not deposing properly #2926

Open mohsinnaqvi0606 opened 1 year ago

mohsinnaqvi0606 commented 1 year ago

Trying to call Splash Screen from Dashboard(restart App) but Splash controller already exist

Navigating from Splash to Dashboard Screen I am using this code Get.off(()=> Dashboard());

While Navigating from DashboardSplash to Splash Screen (To perform restart app) I am using this code Get.offAll(()=> Splash());

GetxController is not disposed here. I am unable to use life cycle of controller as it already exist. I also confirmed it by calling SplashController controller = Get.find();

Flutter: 3.13.4 GetX: 4.6.6

hayatbangash55 commented 1 year ago

I am also facing this issue

mohsinnaqvi0606 commented 1 year ago

@jonataslaw This issue only exist in unNamed routing. I tried Named routing and it's working properly

Define route like this in GetMaterialApp

initialRoute: '/',
      getPages: [
        GetPage(name: '/', page: () => Splash()),
      ],

Where you want to restart/navigation write this code Get.offAllNamed('/');

abdorizak commented 1 year ago

@jonataslaw This issue only exist in unNamed routing. I tried Named routing and it's working properly

Define route like this in GetMaterialApp

initialRoute: '/',
      getPages: [
        GetPage(name: '/', page: () => Splash()),
      ],

Where you want to restart/navigation write this code Get.offAllNamed('/');

Could you please share a full code and also describe the flutter version?

for mean while you can define inside the main.dart

GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: "Your App Name",
      theme: lightMode,
      initialRoute: AppPages.INITIAL,
      getPages: AppPages.routes,
      themeMode: ThemeMode.system,
      darkTheme: darkMode,
    ),

Getx generates you inside app folder routers folder which will contain two dart file app_pages.dart and app_routers.dart those are responsible app routers please check those.

mohsinnaqvi0606 commented 1 year ago

@jonataslaw This issue only exist in unNamed routing. I tried Named routing and it's working properly Define route like this in GetMaterialApp

initialRoute: '/',
      getPages: [
        GetPage(name: '/', page: () => Splash()),
      ],

Where you want to restart/navigation write this code Get.offAllNamed('/');

Could you please share a full code and also describe the flutter version?

for mean while you can define inside the main.dart

GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: "Your App Name",
      theme: lightMode,
      initialRoute: AppPages.INITIAL,
      getPages: AppPages.routes,
      themeMode: ThemeMode.system,
      darkTheme: darkMode,
    ),

Getx generates you inside app folder routers folder which will contain two dart file app_pages.dart and app_routers.dart those are responsible app routers please check those.

I am using it in GetMaterialApp like this

return GetMaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      // home: SplashView(),
      initialRoute: '/',
      getPages: [
        GetPage(name: '/', page: () => SplashView()),
      ],
    )

Flutter & Getx Versions Flutter: 3.13.4 GetX: 4.6.6

arslandevcrew commented 1 year ago

I am facing same here