1
1
import 'package:dynamicform/business_logic/get_forms_cubit/get_forms_cubit.dart' ;
2
2
import 'package:dynamicform/business_logic/get_forms_cubit/get_forms_state.dart' ;
3
+ import 'package:dynamicform/business_logic/post_form_cubit/post_form_cubit.dart' ;
4
+ import 'package:dynamicform/business_logic/post_form_cubit/post_form_state.dart' ;
3
5
import 'package:dynamicform/core/constants/text_constants.dart' ;
4
6
import 'package:dynamicform/core/model/form_model.dart' ;
5
7
import 'package:dynamicform/core/routes/app_routes.dart' ;
8
+ import 'package:dynamicform/core/utils/show_flushbar.dart' ;
6
9
import 'package:dynamicform/presentation/widgets/custom_text_widget.dart' ;
7
10
import 'package:flutter/material.dart' ;
8
11
import 'package:flutter_bloc/flutter_bloc.dart' ;
@@ -27,67 +30,79 @@ class _ListOfFormsScreenState extends State<ListOfFormsScreen> {
27
30
28
31
@override
29
32
Widget build (BuildContext context) {
30
- return Scaffold (
31
- appBar: AppBar (
32
- title: const CustomText (text: TextConstants .formTemplates),
33
- ),
34
- body: RefreshIndicator (
35
- onRefresh: _onRefresh,
36
- child: BlocBuilder <GetFormsCubit , GetFormsState >(
37
- builder: (context, state) {
38
- if (state is GetFormsLoadingState ) {
39
- return const Center (child: CircularProgressIndicator ());
40
- } else if (state is GetFormsFailureState ) {
41
- return Center (
42
- child: SingleChildScrollView (
43
- physics: const AlwaysScrollableScrollPhysics (),
44
- child: Container (
45
- height: MediaQuery .of (context).size.height - 100 ,
46
- alignment: Alignment .center,
47
- child: CustomText (text: state.failure.getErrorMsg ()),
33
+ return BlocListener <PostFormCubit , PostFormState >(
34
+ listener: (context, postFormState) {
35
+ if (postFormState is PostFormSuccessState ) {
36
+ showFlushBar (
37
+ context,
38
+ postFormState.postFormSuccessModel.message ?? TextConstants .nA,
39
+ );
40
+ }
41
+ },
42
+ child: Scaffold (
43
+ appBar: AppBar (
44
+ title: const CustomText (text: TextConstants .formTemplates),
45
+ ),
46
+ body: RefreshIndicator (
47
+ onRefresh: _onRefresh,
48
+ child: BlocBuilder <GetFormsCubit , GetFormsState >(
49
+ builder: (context, state) {
50
+ if (state is GetFormsLoadingState ) {
51
+ return const Center (child: CircularProgressIndicator ());
52
+ } else if (state is GetFormsFailureState ) {
53
+ return Center (
54
+ child: SingleChildScrollView (
55
+ physics: const AlwaysScrollableScrollPhysics (),
56
+ child: Container (
57
+ height: MediaQuery .of (context).size.height - 100 ,
58
+ alignment: Alignment .center,
59
+ child: CustomText (text: state.failure.getErrorMsg ()),
60
+ ),
48
61
),
62
+ );
63
+ } else if (state is GetFormsSuccessState ) {
64
+ List <DynamicFormModel > forms = state.forms.forms ?? [];
65
+ return forms.isEmpty
66
+ ? const Center (
67
+ child: CustomText (
68
+ text: TextConstants .noFormsAvailable,
69
+ ),
70
+ )
71
+ : ListView .builder (
72
+ physics: const AlwaysScrollableScrollPhysics (),
73
+ itemCount: forms.length,
74
+ itemBuilder: (context, index) {
75
+ return ListTile (
76
+ title: CustomText (
77
+ text: forms[index].formName ?? TextConstants .nA,
78
+ ),
79
+ leading: CustomText (
80
+ text: "${index + 1 }." ,
81
+ ),
82
+ onTap: () {
83
+ BlocProvider .of <PostFormCubit >(context)
84
+ .formIdInDB = forms[index].formId;
85
+ Navigator .pushNamed (
86
+ context, AppRoutes .fillFormScreen,
87
+ arguments: forms[index]);
88
+ },
89
+ trailing:
90
+ const Icon (Icons .arrow_forward_ios, size: 18 ),
91
+ );
92
+ },
93
+ );
94
+ }
95
+
96
+ return SingleChildScrollView (
97
+ physics: const AlwaysScrollableScrollPhysics (),
98
+ child: Container (
99
+ height: MediaQuery .of (context).size.height - 100 ,
100
+ alignment: Alignment .center,
101
+ child: const CustomText (text: TextConstants .noFormsAvailable),
49
102
),
50
103
);
51
- } else if (state is GetFormsSuccessState ) {
52
- List <DynamicFormModel > forms = state.forms.forms ?? [];
53
- return forms.isEmpty
54
- ? const Center (
55
- child: CustomText (
56
- text: TextConstants .noFormsAvailable,
57
- ),
58
- )
59
- : ListView .builder (
60
- physics: const AlwaysScrollableScrollPhysics (),
61
- itemCount: forms.length,
62
- itemBuilder: (context, index) {
63
- return ListTile (
64
- title: CustomText (
65
- text: forms[index].formName ?? TextConstants .nA,
66
- ),
67
- leading: CustomText (
68
- text: "${index + 1 }." ,
69
- ),
70
- onTap: () {
71
- Navigator .pushNamed (
72
- context, AppRoutes .fillFormScreen,
73
- arguments: forms[index]);
74
- },
75
- trailing:
76
- const Icon (Icons .arrow_forward_ios, size: 18 ),
77
- );
78
- },
79
- );
80
- }
81
-
82
- return SingleChildScrollView (
83
- physics: const AlwaysScrollableScrollPhysics (),
84
- child: Container (
85
- height: MediaQuery .of (context).size.height - 100 ,
86
- alignment: Alignment .center,
87
- child: const CustomText (text: TextConstants .noFormsAvailable),
88
- ),
89
- );
90
- },
104
+ },
105
+ ),
91
106
),
92
107
),
93
108
);
0 commit comments