Skip to content

Commit

Permalink
Fix use of AppStore in example
Browse files Browse the repository at this point in the history
  • Loading branch information
zjuwjf committed May 27, 2019
1 parent 5999684 commit df964a8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 23 deletions.
4 changes: 2 additions & 2 deletions example/lib/global_store/action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:fish_redux/fish_redux.dart';
enum GlobalAction { changeThemeColor }

class GlobalActionCreator {
static Action onchangeThemeColor(Color color) {
return Action(GlobalAction.changeThemeColor, payload: color);
static Action onchangeThemeColor() {
return const Action(GlobalAction.changeThemeColor);
}
}
15 changes: 13 additions & 2 deletions example/lib/global_store/reducer.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:ui';

import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';

import 'action.dart';
import 'state.dart';
Expand All @@ -13,5 +14,15 @@ Reducer<GlobalState> buildReducer() {
);
}

GlobalState _onchangeThemeColor(GlobalState state, Action action) =>
state.clone()..themeColor = action.payload;
List<Color> _colors = <Color>[
Colors.green,
Colors.red,
Colors.black,
Colors.blue
];

GlobalState _onchangeThemeColor(GlobalState state, Action action) {
final Color next =
_colors[((_colors.indexOf(state.themeColor) + 1) % _colors.length)];
return state.clone()..themeColor = next;
}
9 changes: 1 addition & 8 deletions example/lib/todo_edit_page/effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ void _onDone(Action action, Context<TodoEditState> ctx) {
}

void _onChangeTheme(Action action, Context<TodoEditState> ctx) {
ctx.state.themeIdx++;
if (ctx.state.themeIdx >= ctx.state.themeColorSlots.length) {
ctx.state.themeIdx = 0;
}
//change global data
GlobalStore.store.dispatch(GlobalActionCreator.onchangeThemeColor(
ctx.state.themeColorSlots[ctx.state.themeIdx]));
//notify todo edit page update data
ToDoEditActionCreator.update(null, null, ctx.state.themeIdx.toString());
GlobalStore.store.dispatch(GlobalActionCreator.onchangeThemeColor());
}
2 changes: 0 additions & 2 deletions example/lib/todo_edit_page/reducer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ TodoEditState _update(TodoEditState state, Action action) {
final TodoEditState newState = state.clone();
newState.toDo.title = update['name'] ?? newState.toDo.title;
newState.toDo.desc = update['desc'] ?? newState.toDo.desc;
final String strThemeIdx = update['themeidx'] ?? newState.themeIdx.toString();
newState.themeIdx = int.tryParse(strThemeIdx);
return newState;
}
10 changes: 2 additions & 8 deletions example/lib/todo_edit_page/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@ class TodoEditState implements GlobalBaseState<TodoEditState> {
@override
Color themeColor;

int themeIdx;
List<Color> themeColorSlots;

@override
TodoEditState clone() {
return TodoEditState()
..nameEditController = nameEditController
..descEditController = descEditController
..focusNodeName = focusNodeName
..focusNodeDesc = focusNodeDesc
..toDo = toDo
..themeIdx = themeIdx
..themeColorSlots = themeColorSlots;
..toDo = toDo;
}
}

Expand All @@ -37,7 +32,6 @@ TodoEditState initState(ToDoState arg) {
state.descEditController = TextEditingController(text: arg?.desc);
state.focusNodeName = FocusNode();
state.focusNodeDesc = FocusNode();
state.themeIdx = 0;
state.themeColorSlots = [Colors.green, Colors.red, Colors.black, Colors.blue];

return state;
}
4 changes: 3 additions & 1 deletion example/lib/todo_list_page/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class PageState implements GlobalBaseState<PageState> {

@override
PageState clone() {
return PageState()..toDos = toDos;
return PageState()
..toDos = toDos
..themeColor = themeColor;
}
}

Expand Down

0 comments on commit df964a8

Please sign in to comment.