当我使用此方法来解决
在构建问题期间调用setState()或markNeedsBuild()
问题,SnackBar
,EdgeAlert
,Toast
不会在多次单击FloatingActionButton
时显示,但是在每次 Hot Reload 之后,主题出现在屏幕上,
_onWidgetDidBuild(Function callback) {
WidgetsBinding.instance.addPostFrameCallback((_) {
callback();
});
}
例如:
body: Builder(
builder: (scaffoldContext) => Column(children: <Widget>[
Container(
child: Text('aaa'),
),
BindingWidget<_HomePageViewModel>(
bindings: <Binding>[
Binding('registerStatus', bindableBase,
_HomePageViewModel.registerStatusProperty,
bindingDirection: BindingDirection.TwoWay,
valueConverter: _NumberValueConverter())
],
builder: (bc) {
_onWidgetDidBuild(() {
var registerStatus =
BindingWidget.of<_HomePageViewModel>(bc)
.getValue('registerStatus') as String;
print('2) $registerStatus');
switch(int.parse(registerStatus)){
case 1:
EdgeAlert.show(context, title: 'Title', description: 'Description', gravity: EdgeAlert.TOP);
/*
Scaffold.of(scaffoldContext).showSnackBar(
SnackBar(
content: Text('dddddd'),
backgroundColor: Colors.red,
),
);*/
/* Toast */
break;
}
});
return Container();
}),
])),
我该如何为我的代码解决此问题?
预先感谢