Is there any way for me to create different splash screen for multiple flavor in flutter?
CodePudding user response:
You can use Platform.isAndroid
to check if you are on android and return a different value if not, in the build method of your splashscreen:
void main(){
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: const SplashScreen(),
);
}
}
// splash screen that returns separate widgets for different platforms
class SplashScreen extends StatelessWidget {
const SplashScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Platform.isAndroid
? const AndroidSplashScreen()
: const IosSplashScreen();
}
}
now you can define AndroidSplashScreen
and IosSplashScreen
such that each of them is customized according to the platform.
CodePudding user response:
on main.dart
import 'dart:io';
Widget splashScreen = DefaultSplash();
void main() async {
...
if (Platform.isIOS) {
splashScreen = SplashScreenIOS();
} else if (Platform.isAndroid) {
splashScreen = SplashScreenAndroid();
}
...
}
then in MyApp class
MaterialApp(
home : splashScreen
)
CodePudding user response:
Use flutter_native_splash
package. click here.