动画启动画面颤动

Osa*_*mal 6 splash-screen dart flutter

我想显示一个动画的启动画面,所以我尝试了一个gif图像,但它不起作用,所以我看了一下答案。是否可以将GIF格式的图像添加为启动画面, 但它不起作用,是否有推荐的方法为了达成这个

Mar*_*arc 4

我会选择 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)

  • 首先,如果答案必须有代码,那么很多有用的答案一开始就不会存在。虽然您无法为原生“启动画面”设置动画,但您可以轻松地在其后面添加“您自己的启动画面”,这样用户甚至看不到差异。 (3认同)