I've checked all the other answers about grey screen when hosting a web app but I have not found a solution for my problem yet. I have checked my code for errors, and fixed the ones that I had.
When I deploy my app, everything seems fine. The loginscreen appears and I can succesfully log in and get directed to my homescreen. But when I refresh my browser the screen turns grey and I have to deploy my app again to get it to work.
Hope somebody has some clue to what this can be?
Some further testing in Debugmode get me this error:
The following TypeErrorImpl was thrown building Builder: Unexpected null value. The relevant error-causing widget was: MaterialApp MaterialApp:file:///C:/Users//lib/main.dart:50:12
void main() async {
WidgetsFlutterBinding.ensureInitialized();
SharedPreferences sharedpreference = await SharedPreferences.getInstance();
sharedpreference.getString('email');
await Firebase.initializeApp( options: const FirebaseOptions(
apiKey: "AI******YSpsnJ8",
appId: "1:981*******50",
messagingSenderId: "******",
projectId: "tdfsfdf**",
),
);
if (kIsWeb) {
print('Web');
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]
).then((_) => runApp(const MyApp()));
} else {
print('mobil');
// NOT running on the web! You can check for additional platforms here.
runApp(const MyApp());
}
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: FirebaseAuth.instance.currentUser == null
? const UserLoginPage()
: const UserHomePage(),
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: UserLoginPage.id,
routes:{
UserLoginPage.id : (context) => const UserLoginPage(),
AdminServicePage.id : (context) => const AdminServicePage(),
AdminToolsPage.id : (context) => const AdminToolsPage(),
AdminDeviationPage.id : (context) => const AdminDeviationPage(),
AdminUsersPage.id : (context) => const AdminUsersPage(),
UserHomePage.id : (context) => const UserHomePage(),
UserToolListPage.id : (context) => const UserToolListPage(),
WebHomePage.id : (context) => const WebHomePage(),
WebOverviewPage.id : (context) => const WebOverviewPage(),
},
debugShowCheckedModeBanner: false,
);
}
}