skip to Main Content

I developed a mobile application. I wanted to try it on my own Android phone by converting it to an APK. However, when I open it on my phone, the app is stuck on a white screen. Why could this be?

main.dart:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
  if (FirebaseAuth.instance.currentUser != null) {
    var status = await Permission.location.status;
    if (status.isGranted) {
      getUserLocation();
    } else {
      return;
    }
  } else {
    return;
  }
  runApp(const App());
}

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

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      theme: ThemeData(
        fontFamily: "Roboto",
        appBarTheme: const AppBarTheme(
          centerTitle: true,
          elevation: 0,
          backgroundColor: backgroundWhite,
        ),
        navigationBarTheme: NavigationBarThemeData(
          elevation: 50,
          indicatorColor: mediumRed,
          labelTextStyle: MaterialStateProperty.all(
            const TextStyle(fontSize: 17),
          ),
        ),
      ),
      debugShowCheckedModeBanner: false,
      home: const LayoutPage(),
    );
  }
}

While running my application on the emulator on the computer, it sometimes, not always, gets stuck on the Flutter logo.

2

Answers


  1. Probably FirebaseAuth.instance.currentUser is null or you don’t have location permissions granted. You need to request it at some point, otherwise status.isGranted will always be false. Both else statements have a return clause, so the main function will stop it’s execution before runApp call. Hence the white screen that it stucks on.

    Login or Signup to reply.
  2. Flutter default compiler mode is debug mode. Debug mode only works when the phone is connected to the computer. So you should build in release mode. The example below will help.

    flutter run --release 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search