tenhobi / flashcards

FIT CTU · BI-SP1 · BI-SP2 · B172 · B181 – software team project
MIT License
35 stars 8 forks source link

Explore Flutter state container options #26

Closed danbalarin closed 6 years ago

danbalarin commented 6 years ago

Explore some sort of state container (Redux is the most popular for JS), so we can prevent animation bugs and inconsistent view state.

Medium article List of options

Angular should solve this itself, not sure about that. @tenhobi ?

tenhobi commented 6 years ago

I do not know Redux, but I suppose it's something with data flow in and out? In Flutter that can be done using callbacks, but a truth is, that this can be messy with bigger apps.

So we may use something like this.

Btw. issue #12 is about working in "BLoC", which is (I suppose) MVP-alike pattern between view (flutter, angular) and model (some common logic). This a disjointed problem, right? Redux controlls data/event flow and this BLoC controlls comunication between view and model, eg. database etc.

danbalarin commented 6 years ago

I don't know Redux/state containers much neither, but for example iPhone calculator bug was caused exactly by this. And according to that Medium article, "fire-and-forget" animations are faster (less CPU/GPU demanding), than those with callbacks. And yeah, callbacks get pretty messy in bigger projects.

Will take a look on #12.

Maybe @michaldrabina could know something about state containers, huh?

tenhobi commented 6 years ago

12 is about providing data and functionality (e.g. model in MV***), so far as I understand, it should be different.

Okay then, we can use something like Redux, but we have to explore that and determine a way how to use it in the project (and next to #12). 😸 👍

tenhobi commented 6 years ago

There is an artice about this Redux thing. https://medium.com/shift-studio/flutter-redux-and-firebase-cloud-firestore-in-sync-2c1accabdac4

tenhobi commented 6 years ago

All material widgets use callbacks to comunicate with its parents etc. so we might do it as well, at least in the beginning. Usin' something like redux would mean that we would have to learn something new, something quite complex.

So we will do things like Flutter's material widgets do and can switch to something like Redux it we would have some complications etc.

Souds ok, @Kenny11CZ ? (you can close it if you agree)

tenhobi commented 6 years ago

Example:

class Counter extends StatefulWidget {
  @override
  _CounterState createState() => new _CounterState();
}

class _CounterState extends State<Counter> {
  int _counter = 0;

  void _increment() { // this
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Row(
      children: <Widget>[
        new RaisedButton(
          onPressed: _increment, // this
          child: new Text('Increment'),
        ),
        new Text('Count: $_counter'),
      ],
    );
  }
}
danbalarin commented 6 years ago

Sure, we can add it later if needed, so...