stacked icon indicating copy to clipboard operation
stacked copied to clipboard

Hot Reload causes the app to go back to its home screen, instead of staying on the current page.

Open javdhu opened this issue 6 years ago • 6 comments

The MaterialApp in my main.

return MaterialApp(
              navigatorKey: locator<NavigationService>().navigatorKey,
              initialRoute: autorouter.Routes.startUpViewRoute,
              onGenerateRoute: autorouter.Router().onGenerateRoute,
              //home: StartUpView(),
            );

Issue persists even while only using ExtendedNavigator from the autoroute library.

javdhu avatar Sep 08 '20 20:09 javdhu

@jdaev I've never seen that. Only pressing the restart button in the IDE is when that happens to me. When I save a file "causing hot reload" this doesn't happen. Sounds like a flutter issue.

FilledStacks avatar Sep 09 '20 03:09 FilledStacks

I have the same problem on the latest stable and beta version. Downgrading to older versions doesn't solve it.

javdhu avatar Sep 09 '20 17:09 javdhu

Very strange. i've been developing all day on the mobile apps and it stays on the view where i save the file

FilledStacks avatar Sep 10 '20 04:09 FilledStacks

I'm going to close this issue. If you can provide an example I'd be happy to take a look at.

FilledStacks avatar Sep 27 '20 15:09 FilledStacks

Fixed the issue. Problem was that I had a FutureBuilder as an ancestor of my MaterialApp which was initializing Firebase. I moved it inside my StartupView/InitialRoute and that fixed it.

javdhu avatar Sep 27 '20 18:09 javdhu

This issue still happens in all the apps I create in stacked,,, In startup view model it replaces the correct view,, and the hot reload only return me there.. any navigation I do after the startup view gets lost... why this happens??

in your basic app,, it is working fine,,, what goes wrong,, I add firebase config in main,, this is my main view: Note,, Easy localization is not the issue i guess, because it is working fine on another app.. also removing firebase base config does not cause the issue.. not really sure what is it

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await EasyLocalization.ensureInitialized();
  timeago.setLocaleMessages('ar', timeago.ArMessages());
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  FirebaseAppCheck.instance.setTokenAutoRefreshEnabled(true);
  await FirebaseAppCheck.instance.activate(
    androidProvider: AndroidProvider.debug, // Use Debug provider for Android
    appleProvider: AppleProvider.debug, // Use Debug provider for iOS/macOS
  );
  //Disable Crashlytics in debug mode
  await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false);
  FlutterError.onError = (errorDetails) {
    FirebaseCrashlytics.instance
        .recordFlutterFatalError(errorDetails.copyWith(library: 'DEV'));
  };

  await setupLocator();
  locator<AppConfigService>().setAppConfig(
    appEnvironment: AppEnvironment.DEV,
    appName: 'Make It In Emirates',
    description: 'ADNOC Make It In Emirates',
    baseUrl: Constants.apiRoot.dev,
    imagesRootUrl: Constants.imagesUrlRoot.dev,
  );
  setupDialogUi();
  setupBottomSheetUi();
  await Dynatrace().startWithoutWidget(
      configuration:
          Configuration(logLevel: LogLevel.Debug, reportCrash: true));
  runApp(
    EasyLocalization(
      path: 'assets/i18n',
      supportedLocales: const [
        Locale('en'),
        Locale('ar'),
      ],
      fallbackLocale: const Locale('en'),
      useOnlyLangCode: true,
      useFallbackTranslations: false,
      assetLoader: const CodegenLoader(),
      child: const MainApp(),
    ),
  );
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    LocalizationHelper().init(context);
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
    ]);
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      builder: (context, child) {
        final mediaQueryData = MediaQuery.of(context);

        // Take the textScaleFactor from system and make
        // sure that it's no less than 1.0, but no more
        // than 1.5.
        final constrainedTextScaleFactor =
            mediaQueryData.textScaleFactor.clamp(1.0, 1.3);

        return MediaQuery(
          data: mediaQueryData.copyWith(
            textScaleFactor: constrainedTextScaleFactor,
          ),
          child: child!,
        );
      },
      key: UniqueKey(),
      localizationsDelegates: context.localizationDelegates,
      supportedLocales: context.supportedLocales,
      locale: context.locale,
      darkTheme: SystemTheme.darkTheme,
      themeMode: ThemeMode.light,
      theme: SystemTheme.lightTheme,
      navigatorKey: StackedService.navigatorKey,
      localeResolutionCallback:
          (Locale? locale, Iterable<Locale> supportedLocales) {
        for (Locale supportedLocale in supportedLocales) {
          if (supportedLocale.languageCode == locale!.languageCode) {
            return supportedLocale;
          }
        }


        return supportedLocales.first;
      },
      initialRoute: Routes.startupView,
      navigatorObservers: [
        StackedService.routeObserver,
      ],
      onGenerateRoute: StackedRouter().onGenerateRoute,
    );
  }
}

bdairy avatar Jun 11 '25 16:06 bdairy