'Flutter Lottie animated splash screen on Android
I want to add a Lottie animation as a splash screen in a Flutter Android app. I would like it to start before Flutter draws its first frame, so I'm thinking about doing it natively.
I found two examples online but they both use Flutter's deprecated SplashScreen:
I get the following warning message during build:
W/FlutterActivityAndFragmentDelegate(23263): A splash screen was
provided to Flutter, but this is deprecated. See
flutter.dev/go/android-splash-migration for migration steps.
Is there any way to do a splash animation like this video that:
- Accepts Lottie format
- Visible during a cold start before Flutter draws its first frame
- Doesn't use the deprecated Flutter SplashScreen
Things tried that didn't work:
- The documentation for Android 12 SplashScreen only seems to works for Animated Vector Drawable (AVD) format animations.
- The flutter_native_splash package doesn't support the Lottie animation format yet, though the documentation states that they would accept a PR adding support.

Video courtesy of flutter_animated_splash_screen.
Solution 1:[1]
Use the package lottie
Create a stateful Splash Screen:
Now use it as :
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'),
);
}
}
Now in the initState , you can call a function which can navigate to the home/login screen depending on the status of the user or whatever your use-case is.
For eg:
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'),
);
}
}
Call gotoaPage() in the initState
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
