Giter Site home page Giter Site logo

Comments (14)

brianegan avatar brianegan commented on June 20, 2024 5

Yep! You can also see this technique in the example on the README of this package as well. Another option: If your action is static, you can also forego the StoreConnector by accessing the StoreProvider yourself:

StoreProvider.of<AppState>(context).dispatch(Actions.increment)

The StoreConnector is responsible for connecting to the Store and rebuilding on change. Since this function would not change, no need for the connector / rebuilding!

from flutter_redux.

atreeon avatar atreeon commented on June 20, 2024 1

Ha! I forgot that is still up there! I actually wrote it and still use it some days when I need a little zen but...the code is SO bad (I was learning js at the time) that I would like to update just a little before anyone else sees it...I'll update and upload the code sometime next few months and I will let you know :-)

from flutter_redux.

Paul-Todd avatar Paul-Todd commented on June 20, 2024

The example at http://blog.novoda.com/introduction-to-redux-in-flutter/ indicates that the methods should be added to the model then the model called which then has access to the store - is this the correct design?

from flutter_redux.

atreeon avatar atreeon commented on June 20, 2024

Hi, I just tried this out actually but I'm getting a syntax error on the <AppState> generic type.

[dart] Expected to find ';'

          new RaisedButton(child:new Text('load2'), onPressed: () {
            StoreProvider<AppState>.of(context).dispatch(lessonsLoadFsAction);
          })

from flutter_redux.

brianegan avatar brianegan commented on June 20, 2024

Ack, sorry about that, shouldn't code in Github :P

It's StoreProvider.of<AppState>(context).dispatch(lessonsLoadFsAction)

from flutter_redux.

atreeon avatar atreeon commented on June 20, 2024

Thanks Brian for the quick response, unfortunately I'm getting a new error now

[dart] The method 'of' isn't defined for the class 'StoreProvider', but a constructor with that name is defined.

I'm using dart 1 with the following versions

  redux: ^2.1.1
  flutter_redux: ^0.3.6
  redux_thunk: 0.1.1

if I run it using dart 2 (flutter run --preview-dart-2) with the following versions

  redux: ^3.0.0
  flutter_redux: ^0.5.0
  redux_thunk: 0.2.0 

I get the runtime message when it hits any redux code:

  • Using Dart 2 (required) by using the --preview-dart-2 flag
  • Wrapping your MaterialApp with the StoreProvider, rather than an individual Route
  • Providing full type information to your Store, StoreProvider

(I was going to update to flutter master, currently on 0.2.3 but it wasn't immediately obvious how to...let me know if its worth a try)

from flutter_redux.

atreeon avatar atreeon commented on June 20, 2024

Updating to master version worked for me. Many thanks

btw, if anyone wants to know how to set dart 2 in vs code (required for debug) the setting to do this (ctrl + ,)

"dart.previewDart2": true,

from flutter_redux.

brianegan avatar brianegan commented on June 20, 2024

@twistedinferno Hah, ya beat me to it :) Yah, there seems to be a Dart 2 bug on Beta channel that only affects some users. Sorry bout that!

from flutter_redux.

brianegan avatar brianegan commented on June 20, 2024

p.s. This needs to be a thing: https://github.com/twistedinferno/yoda-motivator 😸

from flutter_redux.

atreeon avatar atreeon commented on June 20, 2024

btw, I am calling dispatch in the build function of my widget to load some data (I don't want it loaded when redux initialises as it is not always necessary and may take time), would you say this is a good location for it?

class SplashS extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    StoreProvider
        .of<AppState>(context)
        .dispatch(lessonsLoadFsAction);
    
    return new Scaffold(
        body: new Container(
            child: new Column(

from flutter_redux.

brianegan avatar brianegan commented on June 20, 2024

@twistedinferno I would say it's probably not the best place, because the build method can be called many times, and it would result in fetching the data over and over. If you only need to load the data once, you have two options:

  1. In the StoreConnector widget that needs the data, you can provide an onInit callback to dispatch this action.
  2. Use a StatefulWidget instead, and dispatch the action in the initState method, this can be a bit trickier though

from flutter_redux.

atreeon avatar atreeon commented on June 20, 2024

Thanks again Brian, I'll try that out :-)

from flutter_redux.

brianegan avatar brianegan commented on June 20, 2024

@Paul-Todd Hey there -- did I answer your question? Need more help? Happy to keep this open if so, or close out if you're feeling good.

from flutter_redux.

Paul-Todd avatar Paul-Todd commented on June 20, 2024

Thanks, you that did it - moved all my methods to the model and it hangs together nicely!

I will try the StoreProvider.of() stuff when I get the chance as this looks like a nice way to do it as well.

from flutter_redux.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.