Skip to content

Instantly share code, notes, and snippets.

View juliuscanute's full-sized avatar
💭
I may be slow to respond.

juliuscanute

💭
I may be slow to respond.
View GitHub Profile
@juliuscanute
juliuscanute / app_reducer.dart
Created December 14, 2019 22:12
Create a new state from loaded emotions
final emotionAppReducer = combineReducers<EmotionAppState>([
TypedReducer<EmotionAppState, LoadedEmotions>(_handleLoadedEmotions)
]);
EmotionAppState _handleLoadedEmotions(
EmotionAppState previousState, LoadedEmotions action) {
EmotionAppState state;
state = previousState.copy(
newState: EmotionAppState(details: action.details, loadComplete: true));
return state;
@juliuscanute
juliuscanute / home_page.dart
Created December 14, 2019 22:27
Display progress indicator during data retrieval
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return StoreConnector<EmotionAppState, _ViewModel>(
converter: _ViewModel.fromStore,
builder: (context, vm) {
if (vm.isLoading()) {
widgets.add(
Align(
alignment: Alignment.center,
@juliuscanute
juliuscanute / home_page.dart
Created December 14, 2019 22:29
Display progress indicator during data retrieval view model
class _ViewModel {
final Store<EmotionAppState> store;
const _ViewModel({this.store});
static _ViewModel fromStore(Store<EmotionAppState> store) {
return _ViewModel(store: store);
}
bool isLoading() => !store.state.loadComplete;
}
@juliuscanute
juliuscanute / saved_emotions_list.dart
Created December 14, 2019 22:31
Display retrieved emotions
class SavedEmotionsList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return StoreConnector<EmotionAppState, _ViewModelSavedEmotion>(
converter: _ViewModelSavedEmotion.fromStore,
builder: (context, vm) {
return ListView.builder(
itemBuilder: (BuildContext context, int index) =>
SavedEmotionsListItem(
index: index,
@juliuscanute
juliuscanute / saved_emotions_list.dart
Created December 14, 2019 22:33
Display retrieved emotions view model
class _ViewModelSavedEmotion {
final Store<EmotionAppState> store;
const _ViewModelSavedEmotion({this.store});
static _ViewModelSavedEmotion fromStore(Store<EmotionAppState> store) {
return _ViewModelSavedEmotion(store: store);
}
String getEmotionImage(int index) {
return store.state.details[index].emoji;
}
@juliuscanute
juliuscanute / add_emotion_detail.dart
Created December 14, 2019 22:41
Show selected emoji and emotion
class _AddDetailState extends State<AddDetail> {
@override
Widget build(BuildContext context) {
return StoreConnector<EmotionAppState, _ViewModel>(
converter: _ViewModel.fromStore,
builder: /*...*/
child: Center(
child: Text(
vm.getEmotionType(),
style: TextStyle(fontSize: 72.0),
@juliuscanute
juliuscanute / add_emotion_detail.dart
Created December 14, 2019 22:43
Show selected emoji and emotion
class _ViewModel {
final Store<EmotionAppState> store;
const _ViewModel({this.store});
static _ViewModel fromStore(Store<EmotionAppState> store) {
return _ViewModel(store: store);
}
String getEmotionType() {
return store.state.emoji;
}
@juliuscanute
juliuscanute / view_emotion_detail.dart
Last active December 14, 2019 22:47
View emotion detail
class _ViewDetailState extends State<ViewDetail> {
@override
Widget build(BuildContext context) {
return StoreConnector<EmotionAppState, _ViewModel>(
converter: _ViewModel.fromStore,
builder: (context, vm) {
/*...*/
child: Center(
child: Text(
vm.getEmotionImage(),
@juliuscanute
juliuscanute / view_emotion_detail.dart
Created December 14, 2019 22:48
View emotion detail
class _ViewModel {
final Store<EmotionAppState> store;
const _ViewModel({this.store});
static _ViewModel fromStore(Store<EmotionAppState> store) {
return _ViewModel(store: store);
}
String getEmotionImage() {
int index = store.state.index;
return store.state.details[index].emoji;
@juliuscanute
juliuscanute / saved_emotions_list.dart
Created December 15, 2019 05:48
2.3 Move from screen [2] to [3]
class _ViewModel {
final Store<EmotionAppState> store;
const _ViewModel({this.store});
static _ViewModel fromStore(Store<EmotionAppState> store) {
return _ViewModel(store: store);
}
void addEmotionDescription(String emotionType, String emotionDescription) {
store.dispatch(NavigateToAction.push('/add-emotion', preNavigation: () {
//...
}));