作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 flutter 应用程序中有一个页面,该页面仅用于显示我的应用程序的 Logo ,然后转到另一个页面。出于某种原因,即使它被调用一次,我也无法弄清楚它会多次运行构建方法。
这是代码:
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
有人可以解释这种行为吗?
最佳答案
你应该对待build
方法,好像它会被多次调用。不能保证它只会被调用一次。查看此答案以获取更多详细信息:How to deal with unwanted widget build?
关于Flutter:页面重建不合逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62851317/
CSS: .banner:nth-of-type(1) {background-color:red;} .banner:nth-of-type(2) {background-color:blue;}
在处理 vector.size() aka size_type 时,我需要一些帮助来澄清这个奇怪的比较 vector rebuiltFaces; int rebuildIndex = 1; cout
我认为我在 Java 类 AccessToken 中的 IBM Social Business Toolkit SDK 的方法中发现了错误。有方法 isExpired(int Threshold) 问
我是一名优秀的程序员,十分优秀!