Skip to content

Instantly share code, notes, and snippets.

@daixianceng
Created March 5, 2021 09:04
Show Gist options
  • Save daixianceng/24e3a5d0d4bd8b908080cf763122a89c to your computer and use it in GitHub Desktop.
Save daixianceng/24e3a5d0d4bd8b908080cf763122a89c to your computer and use it in GitHub Desktop.
flutter redux store example
import 'package:flutter/material.dart';
class Store extends ChangeNotifier {
static Store singleton = Store();
Map<dynamic, dynamic> _state = {};
Map<dynamic, dynamic> get state => _state;
void setState(Map<dynamic, dynamic> state) {
_state = {..._state, ...state};
// This call tells the widgets that are listening to this model to rebuild.
notifyListeners();
}
}
@daixianceng
Copy link
Author

Usage:

Store.singleton.state['global_key']; // get global key
Store.singleton.setState({'user': data}); // set global key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment