I am using Flutter for my app. When I start the app the white screen appears first and then the app launches. So I have used flutter_native_splash to overcome the issue of white screen.
But for the first time the flow of the app works fine which describes below:
But when the user loggedIn with email, password and then close the apps (without logout). After that I want that, when user opens the app again then directly the HomePage should appear.
But in my app when user opens the app again then first splash screen appears and then redirects to HomePage. So in this scenario all the things are working but Why splash screen appears every time when user opens the app??
I want only first time when user opens the app splash screen should appear OR when user close the app by loggingOut then splash screen should appear otherwise splash screen should skip and user directly redirects to the HomePage. How to skip the splash screen when we use flutter_native_splash package??
My code for Splash Screen in pubspec.yaml
is as below:
flutter_native_splash:
color: "#000000"
image: assets/images/LOGO.png
android: true
ios: true
android_width: fill
ios_content_mode: scaleAspectFill
My main.dart
file:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
SharedPreferences prefs = await SharedPreferences.getInstance();
var email = prefs.getString('email');
print(email);
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: email == null ? MMSApp() : HomePage(),
routes: {
LoginPage.id: (context) => LoginPage(),
SignupPage.id: (context) => SignupPage(),
HomePage.id: (context) => HomePage()
},
darkTheme: ThemeData(brightness: Brightness.dark),
themeMode: ThemeMode.dark,
));
}
class MMSApp extends StatefulWidget {
@override
_MMSAppState createState() => _MMSAppState();
}
class _MMSAppState extends State<MMSApp> {
@override
void initState() {
super.initState();
//navigateUser();
}
Future navigateUser() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var status = prefs.getBool('isLoggedIn') ?? false;
print(status);
if (status) {
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => HomePage()));
} else {
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => LoginPage()));
}
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
builder: (context, index){
return Scaffold(
body: Center(
child: Text("Welcome", style: TextStyle(fontSize: 25.0, fontWeight: FontWeight.bold,color: Colors.white),),
),
);
},
future: navigateUser(),
);
}
}
It is impossible to skip the splash screen that is set up by the flutter_native_splash package. This splash screen is displayed while Flutter is loading the app, and is removed when the first Flutter frame is ready. All Flutter apps have this initial screen. By default, it is white and the flutter_native_splash package allows you to configure it, but it cannot be removed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.