Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

flutter_redux_template

a new flutter project.

json

models classes need this lines to json generator:

part 'foo.g.dart'; //on imports

factory foo.fromjson(map<string, dynamic> json) => _$foofromjson(json);
map<string, dynamic> tojson() => _$footojson(this);

when model or api classes changes run:

flutter pub run build_runner build --delete-conflicting-outputs

flutter redux

react views

  1. as a performance optimization, the widget can be rebuilt only when the
    viewmodel changes. in order for this to work correctly, you must
    implement == and hashcode for the viewmodel, and set the distinct
    option to true when creating your storeconnector.

  2. use sample method fromstore to encapsulate store.state to viewmodel transformation

@immutable
class _foopageviewmodel {
  final string foo;
  final function dispatcher;

  const _foopageviewmodel(this.foo, this.dispatcher);

  static _foopageviewmodel fromstore(store<appstate> store) {
    return _foopageviewmodel(store.state.foo, (action) => store.dispatch(action));
  }

  @override
  bool operator ==(object other) {
    if (identical(this, other)) return true;

    return other is _foopageviewmodel &&
        other.foo == foo &&
        other.dispatcher == dispatcher;
  }

  @override
  int get hashcode {
    return foo.hashcode ^ dispatcher.hashcode;
  }
}

class foopage extends statelesswidget {
  const foopage({key? key}) : super(key: key);

  @override
  widget build(buildcontext context) {
    return storeconnector<appstate, _foopageviewmodel>(
      distinct: true,
      converter: (store) => _foopageviewmodel.fromstore(store),
      builder: (context, viewmodel) {
        return scaffold(
          body: textbutton(
            child: text(viewmodel.foo),
            onpressed: () => viewmodel.dispatcher(fooaction()),
          )
        );
      },
    );
  }
}

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.