【发布时间】:2020-05-07 20:27:41
【问题描述】:
所以,我想动态更改 systemNavigationBarColor 和 statusBarColor。这是我的尝试:
void systemColors(Orientation orientation) {
print('orientation changed -> $orientation');
if (orientation == Orientation.portrait) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
systemNavigationBarColor: Colors.blue,
statusBarColor: Colors.green,
),
);
} else {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
systemNavigationBarColor: Colors.green,
statusBarColor: Colors.blue),
);
}
现在,在 StatelessWidget 的构建函数中,每次方向改变时,在 return 语句返回 Scaffold 之前,都会调用此函数;我尝试了具有相同结果的 StatefulWidget。
日志证实了这一点。传递给函数的方向也是正确的。
但是,UI 只更新一次,第一次调用函数时,无论是纵向还是横向,UI 都会更新为每个场景的指定颜色。
当方向改变时,虽然调用了函数,但UI并没有更新。
有什么想法吗?
提前谢谢你:)
【问题讨论】: