Flutter SnackBar或Toast仅在每次热装后显示

时间:2019-06-05 05:54:08

标签: flutter

当我使用此方法来解决

  在构建问题期间调用

setState()或markNeedsBuild()

问题,SnackBarEdgeAlertToast不会在多次单击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();
              }),
        ])),

我该如何为我的代码解决此问题?

预先感谢

0 个答案:

没有答案