I’m trying to make the logo fade in, and then fade out, in a Splash Screen.
After this, it would be redirected to another page.
I could not find a way to make it do both in and out fades.
I’d like not to use any dependency to accomplish this as well.
I’ve tried to change the future to accept a parameter, but it didn’t work. Any
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shopperbr1/t.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({Key? key}) : super(key: key);
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
bool animate = false;
@override
void initState() {
super.initState();
fadeInAnimation();
}
Future fadeInAnimation() async {
await Future.delayed(const Duration(seconds: 2));
setState(() {
animate = true;
});
await Future.delayed(const Duration(seconds: 2));
Get.offAll(() => const t());
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AnimatedOpacity(
duration: const Duration(seconds: 1),
opacity: animate ? 1 : 0,
child: const Image(
image: AssetImage('assets/images/transparent_logo.png'),
),
),
],
),
),
);
}
}
Any help would be really appreciated.
3
Answers
with a little help of Flutter documentation https://api.flutter.dev/flutter/widgets/FadeTransition-class.html https://docs.flutter.dev/development/ui/animations/tutorial After complete the widget animation run a function in Flutter and @inkredusk I was able to get what I was looking for. Thanks
Can you try something like this?
Hope that helps !
Here’s my take on it. I’m using package:flutter_animate, which I highly recommend. By passing the completer down into the splash screen, I know when the animation is complete. In the meanwhile, anything that is await’ed above awaiting done.future will be run in parallel with the animation. Make sure the end of the animation is worthy of a hold, as anything taking longer will delay the transition to the real main app while holding on the final frame of the animation.