0

Im trying to dispatch actions based in events, i couldn't find any way to achieve that with out returning a widget. here is the default way of doing it

   StoreConnector<MyAppState,ActionFunc>(
    converter:(store) => () => store.dispatch(myaction),
    builder:(ctx,callback){
    return Center(child:
         RaisedButton(
         onPressed:(){callback();}
         child:,Text("Action !")
      ));
    });
Pompidou
  • 577
  • 4
  • 18

2 Answers2

7

I do it in this way:

final store = StoreProvider.of<AppState>(buildContext);
store.dispatch(UserLogOutAction(buildContext);

Documentation says following: A method that can be called by descendant Widgets to retrieve the Store from the StoreProvider.

Illia Vlasov
  • 251
  • 4
  • 10
0

You can create a middleware and listing to the event and dispatch action from there.

Taym95
  • 2,331
  • 13
  • 14