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
Probably
FirebaseAuth.instance.currentUser
is null or you don’t have location permissions granted. You need to request it at some point, otherwisestatus.isGranted
will always befalse
. Bothelse
statements have areturn
clause, so themain
function will stop it’s execution beforerunApp
call. Hence the white screen that it stucks on.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.