Issue
I use the package flutter_native_splash to display a splash screen. During this time, I want to instantiate a Future and, when it's done, I want to remove the splash screen and build a widget thanks to a FutureBuilder. The problem is that the device displays the splash screen AND the ErrorScreen for few milliseconds (I don't want it) before building the widget.
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late Future<Metadata> futureMetadata;
@override
void initState() {
super.initState();
initialization();
}
void initialization() async {
futureMetadata = fetchMetadata();
FlutterNativeSplash.remove();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: FutureBuilder<Metadata>(
future: futureMetadata,
builder: (BuildContext context, AsyncSnapshot<Metadata> snapshot) {
if (snapshot.hasData) {
return NavBar(data: snapshot.data);
} else {
return const ErrorScreen();
}
}
)
);
}
}
FlutterNativeSplash.remove(); removes the splash screen.
Solution
because you want to remove the splashscreen after it's finished loading I think you want instead of
futureMetadata = fetchMetadata();
FlutterNativeSplash.remove();
do
futureMetadata = fetchMetadata();
await futureMetadata;
FlutterNativeSplash.remove();
Answered By - Ivo Beckers
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.