I have a launcher screen where I check do I have specific data or not. Depending on the result I show different screens
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: LauncherScreen()
);
}
}
class LauncherScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
print("build, build");
Future.delayed(new Duration(milliseconds: 2000), () {
LocalData localData = LocalData();
localData.getCity().then((city) {
if (city != null) {
Const.city = city;
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Home()),
);
} else {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SelectCities()),
);
}
});
});
return Container(
width: double.infinity,
height: double.infinity,
color: Color(GoEngColors.violet));
}
}
My LauncherScreen called twice and as a result, I see my Home or Select city screen appears twice.
What is the reason of such behaviour and how to solve it? Thanks.