Compare old view model and current view model in Flutter redux

Issue

In Flutter-redux, we can use onDidChange and onWillChange to detect changes in store state. But is there a way to detect change in particular properties?

Can I do something like

if(oldViewModel.changedProperty != viewModel.changedProperty)

In react-redux, prevProps and currProps can be checked for differences and perform action based on that.

Solution

// 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.

StoreConnector<AppState, AppState>(
              distinct: true,
              converter: (store) => store.state,
              builder: ),

Answered By – Taym95

Answer Checked By – Jay B. (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *