在 Flutter 中使用 flare_splash_screen 时出错

Error Using flare_splash_screen in Flutter

我使用 Flare 为我的 Flutter 项目创建了一个动画。但是,我在尝试 运行 时遇到错误。动画不工作,只显示带有我使用的徽标的黑屏。

这是我的代码:

import 'package:flare_splash_screen/flare_splash_screen.dart';
import 'package:flutter/material.dart';

void main () {
  runApp(MaterialApp(
    home: SplashScreen(
  'assets/splash.flr',
    (context) => SplashTela(),
    startAnimation: 'intro',
  backgroundColor: Color(0xff3333),
 ),
));
}

class SplashTela extends StatefulWidget {
@override
_SplashTelaState createState() => _SplashTelaState();
}

class _SplashTelaState extends State<SplashTela> {
@override
Widget build(BuildContext context) {
return Scaffold(
  appBar: null,
  body: Container(
    color: Colors.redAccent,
  ),
);
  }
 }

这里是错误:

E/flutter (25496): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: 
'package:flare_splash_screen/flare_splash_screen.dart': Failed assertion: line 113 pos 16: '! 
(isLoading == null && until == null)': isLoading and until are null, pick one ;)
E/flutter (25496): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:40:39)
E/flutter (25496): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
E/flutter (25496): #2      new SplashScreen 
(package:flare_splash_screen/flare_splash_screen.dart:113:16)
E/flutter (25496): #3      main (package:leagueuniverse/main.dart:6:11)
E/flutter (25496): #4      _runMainZoned.<anonymous closure>.<anonymous closure> 
(dart:ui/hooks.dart:229:25)
E/flutter (25496): #5      _rootRun (dart:async/zone.dart:1124:13)
E/flutter (25496): #6      _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (25496): #7      _runZoned (dart:async/zone.dart:1516:10)
E/flutter (25496): #8      runZoned (dart:async/zone.dart:1500:12)
E/flutter (25496): #9      _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:221:5)
E/flutter (25496): #10     _startIsolate.<anonymous closure> (dart:isolate- 
patch/isolate_patch.dart:305:19)
E/flutter (25496): #11     _RawReceivePortImpl._handleMessage (dart:isolate- 
patch/isolate_patch.dart:172:12)
E/flutter (25496): 

你需要通过 until: () => Future.delayed(Duration(seconds: 5)),
或使用 isLoading 演示代码 isLoading https://github.com/jaumard/flare_splash_screen/blob/master/example/lib/isLoading.dart
使用 SplashScreen.navigate
我用官方的例子来测试你的情况

代码片段

void main() {
  runApp(MaterialApp(
    home: SplashScreen.navigate(
      name: 'assets/intro.flr',
      next: (context) => SplashTela(),
      startAnimation: '1',
      backgroundColor: Color(0xff3333),
      until: () => Future.delayed(Duration(seconds: 5)),
    ),
  ));
}

完整的测试代码没有错误

import 'package:flare_splash_screen/flare_splash_screen.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: SplashScreen.navigate(
      name: 'assets/intro.flr',
      next: (context) => SplashTela(),
      startAnimation: '1',
      backgroundColor: Color(0xff3333),
      until: () => Future.delayed(Duration(seconds: 5)),
    ),
  ));
}

class SplashTela extends StatefulWidget {
  @override
  _SplashTelaState createState() => _SplashTelaState();
}

class _SplashTelaState extends State<SplashTela> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: null,
      body: Container(
        color: Colors.redAccent,
      ),
    );
  }
}