如何在flutter redux中从void方法调用调度动作

时间:2019-04-02 10:04:20

标签: dart flutter flutter-redux

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

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);},
                        ),
                      ],
                   )

                 ),

您可以看到我已经塞满了updateRahi方法并在此方法内

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

}

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

1 个答案:

答案 0 :(得分:0)

您可以这样做:

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');
}