-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathresponse_cubit.dart
More file actions
32 lines (28 loc) · 1.04 KB
/
response_cubit.dart
File metadata and controls
32 lines (28 loc) · 1.04 KB
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
31
32
import 'package:bloc/bloc.dart';
import '../../presentation/screens/employees_list_screen.dart';
import '/../repository/data_provider.dart';
import '/business_logic/cubits/response_state.dart';
import '../../data/employee.dart';
class ResponseCubit extends Cubit<ResponseState> {
late List<Employee> employeeList;
final DataProvider dataProvider;
late int currentListIndex;
ResponseCubit(this.dataProvider, this.employeeList)
: super(ResponseState(DataLoadingStates.dataLoading, employeeList)) {
getStateData();
}
Future<void> getStateData() async {
try {
employeeList = await dataProvider
.getEmployeesList(EmployeesListScreen.searchEmployeeListEndpoint);
currentListIndex = employeeList.length;
if (currentListIndex != 0) {
emit(ResponseState(DataLoadingStates.dataLoaded, employeeList));
} else {
emit(ResponseState(DataLoadingStates.loadingFailed, employeeList));
}
} catch (error) {
emit(ResponseState(DataLoadingStates.loadingFailed, employeeList));
}
}
}