wt1.1.2e NumberPicker
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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: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();
|
||||
yield ExerciseLogReady();
|
||||
} else if ( event is ExerciseLogDelete ) {
|
||||
yield ExerciseLogLoading();
|
||||
exerciseRepository.exerciseList.remove(event.exercise);
|
||||
await exerciseRepository.deleteExercise(event.exercise);
|
||||
yield ExerciseLogReady();
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield ExerciseLogError(message: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
part of 'exercise_log_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class ExerciseLogEvent extends Equatable {
|
||||
const ExerciseLogEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ExerciseLogLoad extends ExerciseLogEvent {
|
||||
const ExerciseLogLoad();
|
||||
}
|
||||
|
||||
class ExerciseLogDelete extends ExerciseLogEvent {
|
||||
final Exercise exercise;
|
||||
const ExerciseLogDelete({this.exercise});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exercise];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
part of 'exercise_log_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class ExerciseLogState extends Equatable {
|
||||
const ExerciseLogState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ExerciseLogInitial extends ExerciseLogState {
|
||||
const ExerciseLogInitial();
|
||||
}
|
||||
|
||||
class ExerciseLogLoading extends ExerciseLogState {
|
||||
const ExerciseLogLoading();
|
||||
}
|
||||
|
||||
class ExerciseLogReady extends ExerciseLogState {
|
||||
const ExerciseLogReady();
|
||||
}
|
||||
|
||||
class ExerciseLogError extends ExerciseLogState {
|
||||
final String message;
|
||||
const ExerciseLogError({this.message});
|
||||
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
Reference in New Issue
Block a user