I am developing a flutter app with Getx, on Android and IOS is working fine, but if i use it on web, when I refresh from the browser, I lose the navigation stack and I stay “blocked” in the page, because the arrow icon to go back also disappears. I also lose some data that I passed from previous pages. The ideal for me is to go back to the /home after a browser refresh. This is my main
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
print("Handling a background message: ${message.messageId}");
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await GetStorage.init();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
Controller c = Get.put(Controller());
c.verificaIdDevice();
c.getimpostazioni();
runApp(GetMaterialApp(
locale: const Locale('it', 'IT'),
supportedLocales: const [
Locale('it', 'IT'),
],
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: const Color.fromARGB(255, 33, 150, 243), /* primary: Colors.green */),
//scaffoldBackgroundColor: Colors.blue.shade200
),
localizationsDelegates: GlobalMaterialLocalizations.delegates,
initialRoute: c.apikey.value.isNotEmpty? "/home" : "/screenIniziale",
getPages: [
GetPage(name: '/home', page: () => Home()),
GetPage(name: '/insaddebiti', page: () => InsAddebitiUI()),
GetPage(name: '/listarisorse', page: () => ListaRisorse2()),
GetPage(name: '/other', page: () => Other()),
GetPage(name: '/settings', page: () => SettingsUI()),
GetPage(name: '/targhe', page: () => LetturaTargaUI()),
GetPage(name: '/estrattoconto', page: () => Estrattoconto()),
GetPage(name: '/camera', page: () => ScattaFoto()),
GetPage(name: '/cassa', page: () => CassaUI()),
GetPage(name: '/firma', page: () => Firma(), preventDuplicates: true),
GetPage(name: '/qr', page: () => const QrScanner(), preventDuplicates: true),
GetPage(name: '/infocamera', page: () => RiepilogoCamera()),
GetPage(name: '/docScanner', page: () => DocumentScannerView()),
GetPage(name: '/preventivi', page: () => Preventivi()),
GetPage(name: '/dettaglioPrev', page: () => Dettagliopreventivo()),
GetPage(name: '/firmaPrivacy', page: () => FirmaPrivacy()),
GetPage(name: '/gestionePrezzi', page: () => GestionePrezzi()),
GetPage(name: '/screenIniziale', page: () => const Screeniniziale()),
],
));
}
Tried to do
html.window.onBeforeUnload.listen((event) {
Get.offAllNamed('/home');
});
But it causes errors
Alessandro Cardarelli is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.