Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.3.7 迁移 flutter 2.0 null safety #762

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider","path":"/Users/linyunhe/.pub-cache/hosted/pub.dartlang.org/path_provider-0.4.1/","dependencies":[]}],"android":[{"name":"path_provider","path":"/Users/linyunhe/.pub-cache/hosted/pub.dartlang.org/path_provider-0.4.1/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":[]}],"date_created":"2021-06-08 17:37:57.339650","version":"1.22.6-xianyu"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider","path":"/Users/lingyan/Downloads/flutter/.pub-cache/hosted/pub.flutter-io.cn/path_provider-0.4.1/","dependencies":[]}],"android":[{"name":"path_provider","path":"/Users/lingyan/Downloads/flutter/.pub-cache/hosted/pub.flutter-io.cn/path_provider-0.4.1/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":[]}],"date_created":"2021-07-01 11:18:54.633183","version":"2.2.2"}
8 changes: 4 additions & 4 deletions example/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ Widget createApp() {
/// 2. 参数2 当 AppStore.state 变化时, PageStore.state 该如何变化
page.connectExtraStore<GlobalState>(GlobalStore.store,
(Object pagestate, GlobalState appState) {
final GlobalBaseState p = pagestate;
final GlobalBaseState p = pagestate as dynamic;
if (p.themeColor != appState.themeColor) {
if (pagestate is Cloneable) {
final Object copy = pagestate.clone();
final dynamic copy = pagestate.clone();
final GlobalBaseState newState = copy;
newState.themeColor = appState.themeColor;
return newState;
Expand Down Expand Up @@ -77,7 +77,7 @@ Widget createApp() {
home: routes.buildPage('todo_list', null),
onGenerateRoute: (RouteSettings settings) {
return MaterialPageRoute<Object>(builder: (BuildContext context) {
return routes.buildPage(settings.name, settings.arguments);
return routes.buildPage(settings.name!, settings.arguments);
});
},
);
Expand All @@ -87,7 +87,7 @@ Widget createApp() {
/// 只针对页面的生命周期进行打印
EffectMiddleware<T> _pageAnalyticsMiddleware<T>({String tag = 'redux'}) {
return (AbstractLogic<dynamic> logic, Store<T> store) {
return (Effect<dynamic> effect) {
return (Effect<dynamic>? effect) {
return (Action action, Context<dynamic> ctx) {
if (logic is Page<dynamic, dynamic> && action.type is Lifecycle) {
print('${logic.runtimeType} ${action.type.toString()} ');
Expand Down
19 changes: 9 additions & 10 deletions example/lib/global_store/reducer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ Reducer<GlobalState> buildReducer() {
<Object, Reducer<GlobalState>>{
GlobalAction.changeThemeColor: _onchangeThemeColor,
},
);
)!;
}

List<Color> _colors = <Color>[
Colors.green,
Colors.red,
Colors.black,
Colors.blue
];
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;
if (state.themeColor != null) {
final Color next =
/// todo(不确定)
_colors[((_colors.indexOf(state.themeColor!) + 1) % _colors.length)];
return state.clone()..themeColor = next;
}
return state.clone();
}
6 changes: 3 additions & 3 deletions example/lib/global_store/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import 'dart:ui';
import 'package:fish_redux/fish_redux.dart';

abstract class GlobalBaseState {
Color get themeColor;
set themeColor(Color color);
Color? get themeColor;
set themeColor(Color? color);
}

class GlobalState implements GlobalBaseState, Cloneable<GlobalState> {
@override
Color themeColor;
Color? themeColor;

@override
GlobalState clone() {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/global_store/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'state.dart';
/// 建立一个AppStore
/// 目前它的功能只有切换主题
class GlobalStore {
static Store<GlobalState> _globalStore;
static Store<GlobalState>? _globalStore;

static Store<GlobalState> get store =>
_globalStore ??= createStore<GlobalState>(GlobalState(), buildReducer());
Expand Down
2 changes: 1 addition & 1 deletion example/lib/todo_edit_page/effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Effect<TodoEditState> buildEffect() {
return combineEffects(<Object, Effect<TodoEditState>>{
ToDoEditAction.onDone: _onDone,
ToDoEditAction.onChangeTheme: _onChangeTheme,
});
})!;
}

void _onDone(Action action, Context<TodoEditState> ctx) {
Expand Down
14 changes: 7 additions & 7 deletions example/lib/todo_edit_page/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import '../global_store/state.dart';
import '../todo_list_page/todo_component/component.dart';

class TodoEditState implements GlobalBaseState, Cloneable<TodoEditState> {
ToDoState toDo;
late ToDoState toDo;

TextEditingController nameEditController;
TextEditingController descEditController;
late TextEditingController nameEditController;
late TextEditingController descEditController;

FocusNode focusNodeName;
FocusNode focusNodeDesc;
late FocusNode focusNodeName;
late FocusNode focusNodeDesc;

@override
Color themeColor;
Color? themeColor;

@override
TodoEditState clone() {
Expand All @@ -28,7 +28,7 @@ class TodoEditState implements GlobalBaseState, Cloneable<TodoEditState> {
}
}

TodoEditState initState(ToDoState arg) {
TodoEditState initState(ToDoState? arg) {
final TodoEditState state = TodoEditState();
state.toDo = arg?.clone() ?? ToDoState();
state.nameEditController = TextEditingController(text: arg?.title);
Expand Down
2 changes: 1 addition & 1 deletion example/lib/todo_list_page/effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Effect<PageState> buildEffect() {
return combineEffects(<Object, Effect<PageState>>{
Lifecycle.initState: _init,
PageAction.onAdd: _onAdd,
});
})!;
}

void _init(Action action, Context<PageState> ctx) {
Expand Down
17 changes: 8 additions & 9 deletions example/lib/todo_list_page/flow_adapter/adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import '../todo_component/component.dart';
import 'reducer.dart';
import 'connector.dart';

FlowAdapter<PageState> get adapter =>
FlowAdapter<PageState>(
FlowAdapter<PageState> get adapter => FlowAdapter<PageState>(
reducer: buildReducer(),
view: (PageState state) =>
DependentArray<PageState>(
length: state.itemCount,
builder: (int index) {
return ToDoConnector(index: index) + ToDoComponent();
},
));
view: (PageState state) => DependentArray<PageState>(
length: state.itemCount,
builder: (int index) {
return ToDoConnector(index: index) + ToDoComponent();
},
),
);
10 changes: 5 additions & 5 deletions example/lib/todo_list_page/flow_adapter/connector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import '../todo_component/component.dart';
class ToDoConnector
extends ConnOp<PageState, ToDoState> {

ToDoConnector({this.index});
ToDoConnector({required this.index});

final int index;

@override
ToDoState get(PageState state) {
if (index >= state.toDos.length) {
ToDoState? get(PageState? state) {
if (index >= state!.toDos!.length) {
return null;
}
return state.toDos[index];
return state.toDos?[index];
}

@override
void set(PageState state, ToDoState subState) {
state.toDos[index] = subState;
state.toDos![index] = subState;
}
}
11 changes: 5 additions & 6 deletions example/lib/todo_list_page/flow_adapter/reducer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ import '../todo_component/action.dart' as todo_action;
import '../todo_component/component.dart';

Reducer<PageState> buildReducer() {
return asReducer(<Object, Reducer<PageState>>{
ToDoListAction.add: _add,
todo_action.ToDoAction.remove: _remove
});
return asReducer(<Object, Reducer<PageState>>{ToDoListAction.add: _add, todo_action.ToDoAction.remove: _remove})!;
}

PageState _add(PageState state, Action action) {
final ToDoState toDo = action.payload;
return state.clone()..toDos = (state.toDos.toList()..add(toDo));
final List<ToDoState> list = state.toDos?.toList() ?? [];
list.add(toDo);
return state.clone()..toDos = list;
}

PageState _remove(PageState state, Action action) {
final String unique = action.payload;
return state.clone()
..toDos = (state.toDos.toList()
..toDos = (state.toDos?.toList() ?? []
..removeWhere((ToDoState state) => state.uniqueId == unique));
}
8 changes: 5 additions & 3 deletions example/lib/todo_list_page/list_adapter/reducer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ Reducer<PageState> buildReducer() {
return asReducer(<Object, Reducer<PageState>>{
ToDoListAction.add: _add,
todo_action.ToDoAction.remove: _remove
});
})!;
}

PageState _add(PageState state, Action action) {
final ToDoState toDo = action.payload;
return state.clone()..toDos = (state.toDos.toList()..add(toDo));
List<ToDoState> list = state.toDos?.toList() ?? [];
list.add(toDo);
return state.clone()..toDos = list;
}

PageState _remove(PageState state, Action action) {
final String unique = action.payload;
return state.clone()
..toDos = (state.toDos.toList()
..toDos = (state.toDos?.toList() ?? []
..removeWhere((ToDoState state) => state.uniqueId == unique));
}
1 change: 0 additions & 1 deletion example/lib/todo_list_page/page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:fish_redux/fish_redux.dart';

import 'effect.dart';
import 'list_adapter/adapter.dart';
import 'flow_adapter/adapter.dart';
import 'reducer.dart';
import 'report_component/component.dart';
Expand Down
2 changes: 1 addition & 1 deletion example/lib/todo_list_page/reducer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'todo_component/component.dart';
Reducer<PageState> buildReducer() {
return asReducer(
<Object, Reducer<PageState>>{PageAction.initToDos: _initToDosReducer},
);
)!;
}

PageState _initToDosReducer(PageState state, Action action) {
Expand Down
18 changes: 9 additions & 9 deletions example/lib/todo_list_page/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import 'todo_component/component.dart';

class PageState extends ItemListLike
implements GlobalBaseState, Cloneable<PageState> {
List<ToDoState> toDos;
List<ToDoState>? toDos;

@override
Color themeColor;
Color? themeColor;

@override
PageState clone() {
Expand All @@ -20,7 +20,7 @@ class PageState extends ItemListLike
}

@override
Object getItemData(int index) => toDos[index];
Object getItemData(int index) => toDos?.elementAt(index) as dynamic;

@override
String getItemType(int index) => 'toDo';
Expand All @@ -30,12 +30,12 @@ class PageState extends ItemListLike

@override
ItemListLike updateItemData(int index, Object data, bool isStateCopied) {
toDos[index] = data;
toDos?[index] = data as dynamic;
return this;
}
}

PageState initState(Map<String, dynamic> args) {
PageState initState(Map<String, dynamic>? args) {
//just demo, do nothing here...
return PageState();
}
Expand All @@ -45,15 +45,15 @@ class ReportConnector extends ConnOp<PageState, ReportState>
@override
ReportState computed(PageState state) {
return ReportState()
..done = state.toDos.where((ToDoState tds) => tds.isDone).length
..total = state.toDos.length;
..done = state.toDos?.where((ToDoState tds) => tds.isDone).length ?? 0
..total = state.toDos?.length ?? 0;
}

@override
List<dynamic> factors(PageState state) {
return <int>[
state.toDos.where((ToDoState tds) => tds.isDone).length,
state.toDos.length
state.toDos?.where((ToDoState tds) => tds.isDone).length ?? 0,
state.toDos?.length ?? 0
];
}

Expand Down
6 changes: 3 additions & 3 deletions example/lib/todo_list_page/todo_component/effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Effect<ToDoState> buildEffect() {
return combineEffects(<Object, Effect<ToDoState>>{
ToDoAction.onEdit: _onEdit,
ToDoAction.onRemove: _onRemove,
});
})!;
}

void _onEdit(Action action, Context<ToDoState> ctx) {
Expand All @@ -27,7 +27,7 @@ void _onEdit(Action action, Context<ToDoState> ctx) {
}

void _onRemove(Action action, Context<ToDoState> ctx) async {
final String select = await showDialog<String>(
final String? select = await showDialog<String>(
context: ctx.context,
builder: (BuildContext buildContext) {
return AlertDialog(
Expand All @@ -49,6 +49,6 @@ void _onRemove(Action action, Context<ToDoState> ctx) async {
});

if (select == 'Yes') {
ctx.dispatch(ToDoActionCreator.removeAction(ctx.state.uniqueId));
ctx.dispatch(ToDoActionCreator.removeAction(ctx.state.uniqueId!));
}
}
2 changes: 1 addition & 1 deletion example/lib/todo_list_page/todo_component/reducer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Reducer<ToDoState> buildReducer() {
return asReducer(<Object, Reducer<ToDoState>>{
ToDoAction.edit: _edit,
ToDoAction.done: _markDone
});
})!;
}

ToDoState _edit(ToDoState state, Action action) {
Expand Down
6 changes: 3 additions & 3 deletions example/lib/todo_list_page/todo_component/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:fish_redux/fish_redux.dart';
// import 'package:uuid/uuid.dart';

class ToDoState implements Cloneable<ToDoState> {
String uniqueId;
String title;
String desc;
String? uniqueId;
String? title;
String? desc;
bool isDone;

static int _seed = 202103051044;
Expand Down
6 changes: 3 additions & 3 deletions example/lib/todo_list_page/todo_component/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Widget buildView(
: const Icon(Icons.check_box_outline_blank))(),
),
onTap: () {
dispatch(ToDoActionCreator.doneAction(state.uniqueId));
dispatch(ToDoActionCreator.doneAction(state.uniqueId!));
},
)
],
Expand All @@ -63,7 +63,7 @@ Widget buildView(
child: const Icon(Icons.edit),
),
onTap: () {
dispatch(ToDoActionCreator.onEditAction(state.uniqueId));
dispatch(ToDoActionCreator.onEditAction(state.uniqueId!));
},
)
],
Expand All @@ -72,7 +72,7 @@ Widget buildView(
],
),
onLongPress: () {
dispatch(ToDoActionCreator.onRemoveAction(state.uniqueId));
dispatch(ToDoActionCreator.onRemoveAction(state.uniqueId!));
},
),
);
Expand Down
Loading