Osa*_*mal 6 splash-screen dart flutter
我想显示一个动画的启动画面,所以我尝试了一个gif图像,但它不起作用,所以我看了一下答案。是否可以将GIF格式的图像添加为启动画面, 但它不起作用,是否有推荐的方法为了达成这个
我会选择 Flare ( https://www.2dimensions.com/about-flare ) 方式。您可以使用免费的网络创作工具非常简单地创作动画。
然后他们有一个 Flutter 运行时插件(https://pub.dev/packages/flare_flutter)。有了它,您就可以播放从创作 Web 应用程序导出的动画。一旦您掌握了如何使用网络创作工具,这真的很容易。无论如何,它比 100% 使用代码创建动画更容易。
这就是启动画面的样子(假设您将耀斑动画导出放在项目文件夹的 /assets/flare 中)
import 'package:flare_flutter/flare_actor.dart';
import 'package:flutter/material.dart';
class SplashScreen extends StatelessWidget {
SplashScreen() {
}
@override
Widget build(BuildContext context) {
String asset = "assets/flare/splash.flr";
return Container(
// use same color as native splashscreen GIF/PNG so that the user cant tell the difference
color: const Color.fromRGBO(250, 224, 61, 1.0),
child: FlareActor(
asset,
callback: (nameOfAnimation) async {
Navigator.pushReplacementNamed(context, "/login");
},
fit: BoxFit.contain,
alignment: Alignment.center,
sizeFromArtboard: false,
animation: "splash",
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
在你的materialApp中只需执行以下操作:
return MaterialApp(
title: 'My App',
debugShowCheckedModeBanner: false,
home: SplashScreen()
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4267 次 |
| 最近记录: |