Open Akiat opened 3 years ago
I am also experiencing the same
That's weird I can't reproduce it, temporarily you can make a variable that becomes true if the function ran and prevent the function from running again, but I will try to investigate it also Thanks for reporting
Yes this is what I use to avoid multiple calls 👍
I am also experiencing the same behaviour. This is how it happens for me:
Future<Widget> loadApplicationWithScreenToNavigate() async {
printError(info: "Called");
return Future.value(Home());
}
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Some title',
debugShowCheckedModeBanner: false,
theme: buildThemeData(),
home: SplashScreen(
navigateAfterFuture: loadApplicationWithScreenToNavigate(),
backgroundColor: Colors.white,
);
And in console I can see sometimes it's being called 2 times, sometimes 3 times.
P.S. Code above is pseudo code just to demonstrate the reproduction of this issue,
Probably that the state changes and redraws the widget thus calling your Future
again 🤔
I agree with @kuromukira , it should be a State
issue.
A quick workaround worked for me : Setting a boolean to true
as soon as the Future is called, and not calling the Future if the boolean is true
:
class _SplashScreenPageState extends State<SplashScreenPage> {
bool credentialsCalled = false ;
Future<Widget> _retrieveCredentials() async {
if (!credentialsCalled) {
await Requests().getCredentials();
credentialsCalled = true;
}
return SearchPage();
}
@override
Widget build(BuildContext context) {
return SplashScreen(
navigateAfterFuture: _retrieveCredentials(),
// [...]
);
}
}
First of all thank you for your great package.
The issue The function assigned to navigateAfterFuture is called multiple times (2 or 3 times in my case).
The code
Expected behavior It should call my callback only one time, or I done something wrong.
Thanks for your help 👍