简体   繁体   English

创建一个应用程序来学习在flutter应用程序项目中添加rive闪屏动画

[英]Created an application to learn to add rive splash screen animations in flutter app project

I followed the tutorial of adding a splash screen in an app in flutter using rive animation tool, but the splash screen won't show up.我按照使用 rive 动画工具在 Flutter 中添加启动画面的教程进行操作,但启动画面不会出现。

Link which i followed:- https://pub.dev/packages/rive_splash_screen我关注的链接:- https://pub.dev/packages/rive_splash_screen

Code in main.dart file main.dart 文件中的代码

import 'package:flutter/material.dart';
import 'package:rive_splash_screen/rive_splash_screen.dart';
import 'package:rive/rive.dart';
import 'dart:ui';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: SplashScreen.navigate(
        name: 'assets/doublersplashscreen.riv',
        next: (_) => const MyHomePage(),
        until: () => Future.delayed(const Duration(seconds: 5)),
        startAnimation: 'Splash',
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.red,
      height: 400,
      width: 300,
    );
  }
}

Code in pubspec.yaml file pubspec.yaml 文件中的代码

Code in pubspec.yaml file pubspec.yaml 文件中的代码

I have used your code and a sample rive's community-made animation to reproduce the issue.我已使用您的代码和示例 rive 社区制作的动画来重现该问题。 But I could not, and everything worked as expected.但我做不到,一切都按预期进行。 So please check the following steps:所以请检查以下步骤:

1- Be sure that your animation path is added correctly to pubspec.yaml : 1-确保您的动画路径正确添加到pubspec.yaml

pubspec.yaml

flutter:

  uses-material-design: true
 
  assets:
    - assets/

2- Be sure that the riv file's path is written accurately in the SplashScreen.navigate widget. 2- 确保riv文件的路径准确地写入SplashScreen.navigate小部件。 Check if there is an uppercase in the provided path.检查提供的路径中是否有uppercase

home: SplashScreen.navigate(
  name: 'assets/alarm.riv',
  next: (_) => const MyHomePage(title: 'Demo App'),
  until: () => Future.delayed(const Duration(seconds: 5)),
  startAnimation: 'bell',
),

3- Lastly, even if this can not be causing this problem, be sure that you are providing the correct animation name. 3- 最后,即使这不会导致此问题,请确保您提供正确的动画名称。 If you don't, animation will show up but won't animate as expected.如果你不这样做,动画会出现,但不会像预期的那样动画。

Check the following repository on Github .检查Github上的以下存储库。

If you have further problems, please don't hesitate to write in the comments.如果您还有其他问题,请不要犹豫,在评论中写下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM