【问题标题】:how to call dispatch action from a void method in flutter redux如何从flutter redux中的void方法调用调度动作
【发布时间】:2019-04-02 10:04:20
【问题描述】:

我正在尝试从方法执行调度操作。这是我正在尝试的方法

StoreConnector<AppState, AppState>(
                   converter: (store) => store.state,
                   builder: (context, items) => Column(
                      children: <Widget>[
                        Text(items.rahi),
                        Text(items.mySiteUrl),
                        RaisedButton(
                          child: Text('update rahi'),
                         onPressed: (){_updateRahi(store);},
                        ),
                      ],
                   )

                 ),

你可以看到我已经 cakked updateRahi 方法和这个方法里面

void _updateRahi(store){
  var text = status.text; 
  // want to call dispatch action from here
  store.dispatch('this is some texts');

}

我想调用调度动作。我怎么能从这里打电话?谢谢。

【问题讨论】:

    标签: dart flutter flutter-redux


    【解决方案1】:

    你可以这样做:

    import 'package:flutter_redux/flutter_redux.dart';

    StoreConnector<AppState, AppState>(
      converter: (store) => store.state,
      builder: (context, items) => Column(
        children: <Widget>[
          Text(items.rahi),
          Text(items.mySiteUrl),
          RaisedButton(
            child: Text('update rahi'),
            onPressed: (){_updateRahi();},
          ),
        ],
      )
    ),
    
    void _updateRahi(){
      final store = StoreProvider.of<AppState>(context);
      var text = status.text; 
    
      store.dispatch('this is some texts');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      • 2020-04-26
      • 2021-10-06
      • 2021-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多