如何从flutter redux中的void方法调用dispatch动作

问题描述 投票:0回答:1

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

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个回答
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');
}
© www.soinside.com 2019 - 2024. All rights reserved.