-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathspeaker_cubit.dart
30 lines (28 loc) · 1.11 KB
/
speaker_cubit.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import 'package:bloc/bloc.dart';
import 'package:ecellapp/core/res/errors.dart';
import 'package:ecellapp/core/res/strings.dart';
import 'package:ecellapp/core/utils/logger.dart';
import 'package:ecellapp/models/speaker.dart';
import 'package:ecellapp/screens/speaker/speaker_repository.dart';
import 'package:equatable/equatable.dart';
part 'speaker_state.dart';
class SpeakerCubit extends Cubit<SpeakerState> {
final SpeakerRepository _speakerRepository;
SpeakerCubit(this._speakerRepository) : super(SpeakerInitial());
Future<void> getSpeakerList() async {
try {
emit(SpeakerLoading());
List<Speaker> speakerList = await _speakerRepository.getAllSpeakers();
speakerList.sort((a,b)=>(b.year!.toInt())-(a.year!.toInt()));
emit(SpeakerSuccess(speakerList));
} on NetworkException {
emit(SpeakerError(S.networkException));
} on ValidationException catch (e) {
emit(SpeakerError(e.description));
} on UnknownException {
emit(SpeakerError(S.unknownException));
} catch (e) {
Log.s(tag: "Speaker Cubit", message: "Unknown Error message:" + e.toString());
}
}
}