getx icon indicating copy to clipboard operation
getx copied to clipboard

if you are running your app on a physical device or emulator, you must exchange your [MaterialApp] for a [GetMaterialApp] but GetMaterialApp if exist

Open Siavichay7 opened this issue 3 years ago • 4 comments

ATTENTION: DO NOT USE THIS FIELD TO ASK SUPPORT QUESTIONS. USE THE PLATFORM CHANNELS FOR THIS. THIS SPACE IS DEDICATED ONLY FOR BUGS DESCRIPTION. Fill in the template. Issues that do not respect the model will be closed.

Describe the bug You are trying to use contextless navigation without a GetMaterialApp or Get.key. If you are testing your app, you can use: [Get.testMode = true], or if you are running your app on a physical device or emulator, you must exchange your [MaterialApp] for a [GetMaterialApp].

**Reproduction code Get.toNamed("/configuracion");

example:


Future<void> main() async {
  // WidgetsFlutterBinding.ensureInitialized();
  await GetStorage.init();
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  runApp(TendaGo());
}

class TendaGo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    Get.put(GlobalController());
    return GetMaterialApp(
      initialRoute: '/splash',
      translations: Messages(),
      locale: Get.deviceLocale,
      fallbackLocale: Locale('en'),
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: [
        const Locale('es', 'ES'), // Arabic, no country code
      ],
      theme: ThemeData(
          primaryIconTheme: IconThemeData(
        color: Colors.white,
      )),
      debugShowCheckedModeBanner: false,
      title: 'Tenda Go',
      home: SplashPage(),
      initialBinding: SplashBinding(),
      getPages: AppPages.pages,
    );
  }
}

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Flutter Version: Enter the version of the Flutter you are using

Getx Version: ^4.6.1

Describe on which device you found the bug: ex: All

Minimal reproduce code Provide a minimum reproduction code for the problem Captura de Pantalla 2022-02-23 a la(s) 15 19 32

Siavichay7 avatar Feb 23 '22 20:02 Siavichay7

Maybe you are calling the navigator before the GetMaterialApp is attached. Would you be calling Get.toNamed("/configuracion"); in onInit or class constructor?

jonataslaw avatar Feb 23 '22 20:02 jonataslaw

Maybe you are calling the navigator before the GetMaterialApp is attached. Would you be calling Get.toNamed("/configuracion"); in onInit or class constructor?

Get.toNamed("/configuracion"); is called in onPress in a button but don't work

Siavichay7 avatar Feb 23 '22 20:02 Siavichay7

Maybe you are calling the navigator before the GetMaterialApp is attached. Would you be calling Get.toNamed("/configuracion"); in onInit or class constructor? Captura de Pantalla 2022-02-23 a la(s) 15 27 49

Siavichay7 avatar Feb 23 '22 20:02 Siavichay7

I think the problem is probably that you are trying to navigate with contextless. If you are trying to move from the splashscreen controller to the HomePage (for example), you can wrap Get.to() inside a Future, and this will automatically make it time for GetMaterialApp to be loaded. This worked for me.

Ismaelito86 avatar Jul 03 '24 14:07 Ismaelito86