-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathemployee_bloc_builder.dart
More file actions
60 lines (56 loc) · 1.92 KB
/
employee_bloc_builder.dart
File metadata and controls
60 lines (56 loc) · 1.92 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../widgets/list_item.dart';
import '../../business_logic/cubits/response_cubit.dart';
import '../../business_logic/cubits/response_state.dart';
class EmployeeBlocBuilder extends StatelessWidget {
const EmployeeBlocBuilder({
Key? key,
}) : super(key: key);
// use cubit dataprovider
// move deleteEmployeeEntry to ResponseCubit
@override
Widget build(BuildContext context) {
return BlocBuilder<ResponseCubit, ResponseState>(
builder: (context, state) {
if (state.dataState == DataLoadingStates.dataLoaded) {
return RefreshIndicator(
onRefresh: () => context.read<ResponseCubit>().getStateData(),
child: ListView.builder(
itemBuilder: (ctx, index) {
return ListItem(
index: index,
employeeList: state.employeeList,
);
},
itemCount: state.employeeList.length,
),
);
} else if (state.dataState == DataLoadingStates.dataLoading) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Theme.of(context).primaryColor),
),
const SizedBox(height: 5),
Text(
'Data loading',
style: Theme.of(context).textTheme.headline6,
),
],
));
} else {
return RefreshIndicator(
onRefresh: () => context.read<ResponseCubit>().getStateData(),
child: Center(
child: Text('Data loading failed',
style: Theme.of(context).textTheme.headline6)),
);
}
},
);
}
}