41 lines
1.3 KiB
Dart
41 lines
1.3 KiB
Dart
import 'dart:async';
|
|
import 'package:aitrainer_app/model/exercise.dart';
|
|
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
|
import 'package:bloc/bloc.dart';
|
|
import 'package:equatable/equatable.dart';
|
|
import 'package:flurry/flurry.dart';
|
|
import 'package:meta/meta.dart';
|
|
|
|
part 'exercise_log_event.dart';
|
|
|
|
part 'exercise_log_state.dart';
|
|
|
|
class ExerciseLogBloc extends Bloc<ExerciseLogEvent, ExerciseLogState> {
|
|
final ExerciseRepository exerciseRepository;
|
|
@override
|
|
ExerciseLogBloc({this.exerciseRepository}) : super(ExerciseLogInitial());
|
|
|
|
@override
|
|
Stream<ExerciseLogState> mapEventToState(ExerciseLogEvent event) async* {
|
|
try {
|
|
if (event is ExerciseLogLoad) {
|
|
yield ExerciseLogLoading();
|
|
Flurry.logEvent("exerciseLog");
|
|
yield ExerciseLogReady();
|
|
} else if (event is ExerciseLogDelete) {
|
|
yield ExerciseLogLoading();
|
|
exerciseRepository.exerciseList.remove(event.exercise);
|
|
await exerciseRepository.deleteExercise(event.exercise);
|
|
Flurry.logEvent("exerciseDelete");
|
|
yield ExerciseLogReady();
|
|
} else if (event is ExerciseResult) {
|
|
yield ExerciseLogLoading();
|
|
Flurry.logEvent("exerciseResult");
|
|
yield ExerciseLogReady();
|
|
}
|
|
} on Exception catch (e) {
|
|
yield ExerciseLogError(message: e.toString());
|
|
}
|
|
}
|
|
}
|