1

我使用 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): 
4

1 回答 1

0

您需要通过until: () => Future.delayed(Duration(seconds: 5)),
或使用https://github.com/jaumard/flare_splash_screen/blob/master/example/lib/isLoading.dartisLoading的演示代码 使用 我使用官方示例来测试您的案例isLoading
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,
      ),
    );
  }
}
于 2019-12-19T01:44:33.913 回答