From 86668681845f579290ff3c3d50cc4e0f50e09192 Mon Sep 17 00:00:00 2001 From: Lijun Date: 2022年2月28日 14:43:47 +0800 Subject: [PATCH 1/2] Fix: Replace the reference to FlutterApplication in the application tag with ${applicationName}. --- android/app/src/main/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index c4dd8ee..fbaa36f 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -11,7 +11,7 @@ Date: 2022年3月11日 11:16:26 +0800 Subject: [PATCH 2/2] mapEventToState deprecated --- lib/blocs/habit/habit_bloc.dart | 41 ++++++++++++++------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/lib/blocs/habit/habit_bloc.dart b/lib/blocs/habit/habit_bloc.dart index 22bd567..b94ac84 100644 --- a/lib/blocs/habit/habit_bloc.dart +++ b/lib/blocs/habit/habit_bloc.dart @@ -7,52 +7,45 @@ import 'package:timefly/models/user.dart'; class HabitsBloc extends Bloc { ///初始化状态为正在加载 - HabitsBloc() : super(HabitsLoadInProgress()); - - @override - Stream mapEventToState(HabitsEvent event) async* { - if (event is HabitsLoad) { - yield* _mapHabitsLoadToState(); - } else if (event is HabitsAdd) { - yield* _mapHabitsAddToState(event); - } else if (event is HabitUpdate) { - yield* _mapHabitUpdateToState(event); - } + HabitsBloc() : super(HabitsLoadInProgress()) { + on(_mapHabitsLoadToState); + on(_mapHabitsAddToState); + on(_mapHabitUpdateToState); } - Stream _mapHabitsLoadToState() async* { + void _mapHabitsLoadToState( + HabitsLoad event, Emitter emit) async { try { if (!SessionUtils.sharedInstance().isLogin()) { - yield HabitLoadSuccess([]); + emit(HabitLoadSuccess([])); return; } List habits = await DatabaseProvider.db.getAllHabits(); print(habits); - yield HabitLoadSuccess(habits); + emit(HabitLoadSuccess(habits)); } catch (e) { print(e); - yield HabitsLodeFailure(); + emit(HabitsLodeFailure()); } } - Stream _mapHabitsAddToState(HabitsAdd habitsAdd) async* { + void _mapHabitsAddToState(HabitsAdd event, Emitter emit) { if (state is HabitLoadSuccess) { final List habits = List.from((state as HabitLoadSuccess).habits) - ..add(habitsAdd.habit); - yield HabitLoadSuccess(habits); - DatabaseProvider.db.insert(habitsAdd.habit); + ..add(event.habit); + emit(HabitLoadSuccess(habits)); + DatabaseProvider.db.insert(event.habit); } } - Stream _mapHabitUpdateToState(HabitUpdate habitUpdate) async* { + void _mapHabitUpdateToState(HabitUpdate event, Emitter emit) { if (state is HabitLoadSuccess) { final List habits = (state as HabitLoadSuccess) .habits - .map((habit) => - habit.id == habitUpdate.habit.id ? habitUpdate.habit : habit) + .map((habit) => habit.id == event.habit.id ? event.habit : habit) .toList(); - yield HabitLoadSuccess(habits); - DatabaseProvider.db.update(habitUpdate.habit); + emit(HabitLoadSuccess(habits)); + DatabaseProvider.db.update(event.habit); } } }

AltStyle によって変換されたページ (->オリジナル) /