Col*_*son 9 android flutter lottie
我想在 Flutter Android 应用程序中添加 Lottie 动画作为启动屏幕。我希望它在 Flutter 绘制第一帧之前启动,所以我正在考虑在本地执行此操作。
我在网上找到了两个例子,但它们都使用了 Flutter 的 deprecated SplashScreen
:
我在构建过程中收到以下警告消息:
W/FlutterActivityAndFragmentDelegate(23263): A splash screen was
provided to Flutter, but this is deprecated. See
flutter.dev/go/android-splash-migration for migration steps.
Run Code Online (Sandbox Code Playgroud)
有没有办法制作像这个视频这样的启动动画:
尝试过但不起作用的事情:
创建一个有状态的启动屏幕:
现在将其用作:
import 'package:lottie/lottie.dart';
import 'package:flutter/material.dart';
class Example extends StatefulWidget {
const Example({Key? key}) : super(key: key);
@override
State<Example> createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
String loadingString = 'Loading.....';
Duration delayInterval = const Duration(milliseconds: 2000);
@override
Widget build(BuildContext context) {
return Container(
child: Lottie.asset('images/ex.json'),
);
}
}
Run Code Online (Sandbox Code Playgroud)
现在initState
,您可以调用一个函数,该函数可以根据用户的状态或您的用例导航到主/登录屏幕。
例如:
void gotoaPage() async {
dynamic cookie = global.prefs!.getString('something');
if (cookie != null) {
loadingString;
await Future.delayed(delayInterval);
Future(
() => Navigator.of(context).pushReplacementNamed('/home'),
);
} else {
await Future.delayed(delayInterval);
Future(
() => Navigator.of(context).pushReplacementNamed('/login'),
);
}
}
Run Code Online (Sandbox Code Playgroud)
致电gotoaPage()
initState
归档时间: |
|
查看次数: |
5628 次 |
最近记录: |