У меня есть страница в моем приложении Flutter, созданная только для отображения lo go моего приложения, а затем go на другую страницу. По какой-то причине я не могу понять, что он запускает метод сборки несколько раз, даже если он вызывается один раз.
Вот код:
class LoadingPage extends StatelessWidget {
int i = 0;
@override
Widget build(BuildContext context) {
i++;
print(i);
test(context);
test2();
return Scaffold(
backgroundColor: Colors.lightBlue,
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Image.asset("assets/images/logo.png"),
SizedBox(
height: Responsive.deviceHeight(context) * 0.05,
),
LoadingRotating.square(
backgroundColor: Colors.lightBlue,
borderColor: Colors.white,
borderSize: 5.0,
),
],
),
),
);
}
void test(BuildContext context) {
Future.delayed(const Duration(seconds: 5), () {
print("H");
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (context) => ProductListPage()),
(Route<dynamic> route) => false,
);
});
}
void test2(){
print("H2");
}
}
Я ожидал напечатать следующее:
1
H2
H
Но результат:
I/flutter (20904): 1
I/flutter (20904): H2
I/flutter (20904): 1
I/flutter (20904): H2
I/flutter (20904): H
I/flutter (20904): H
Может кто-нибудь объяснить такое поведение?
Спасибо