闪屏包含跳动中的视频



我正试图在FLUTTER的启动屏幕中添加3秒视频。因此,如何在启动屏幕或任何其他建议中删除启动屏幕前的白色屏幕。

这是我尝试过的

class _MyAppState extends State<MyApp> {
late VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.asset("assets/video.mp4");
_controller.addListener(() {
if (!_controller.value.isPlaying &&
_controller.value.position.inSeconds >=
_controller.value.duration.inSeconds) {
// completion
_controller.dispose();
Get.offAll(() => FirstScreen());
}
});
controller.initialize().then(() => setState(() {}));
_controller.play();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
return GetMaterialApp(
debugShowCheckedModeBanner: false,
home:  Scaffold(
body: VideoPlayer(_controller),
),
);
}
}

你不能完全删除这个屏幕。你唯一能做的就是以某种方式改变它,使它与你的视频播放屏幕相匹配。使用https://pub.dev/packages/flutter_native_splash包,让用户感觉不到屏幕的变化(使背景相同,等等)

首先在android/app/src/main/res/values中创建styles.xml文件

styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a Drawable splash screen on the activity. Automatically removed when Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/splash_screen</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.  -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>

现在添加你的闪屏在res/drawable文件夹。

AndroidManifest.xml

activity标签中像这样创建meta-data

<meta-data android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" android:resource="@drawable/splash_screen" />
<meta-data android:name="flutterEmbedding" android:value="2" />

最新更新