Skip to content

Commit 8caae85

Browse files
committed
Merge branch 'hlm-2981-row-version' of https://github.com/egovernments/health-campaign-field-worker-app into hlm-2981-row-version
2 parents e6c4f24 + b376a98 commit 8caae85

File tree

5 files changed

+130
-103
lines changed

5 files changed

+130
-103
lines changed

apps/health_campaign_field_worker_app/lib/pages/beneficiary_registration/individual_details.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,15 @@ class _IndividualDetailsPageState
349349
appConfiguration.genderOptions ??
350350
<GenderOptions>[];
351351

352-
return DigitReactiveDropdown<String>(
352+
return DigitDropdown<String>(
353353
label: localizations.translate(
354354
i18.individualDetails.genderLabelText,
355355
),
356-
valueMapper: (value) =>
357-
localizations.translate(value),
356+
valueMapper: (value) => value,
358357
initialValue: genderOptions.firstOrNull?.name,
359358
menuItems: genderOptions.map(
360359
(e) {
361-
return e.code;
360+
return localizations.translate(e.name);
362361
},
363362
).toList(),
364363
formControlName: _genderKey,
@@ -501,10 +500,9 @@ class _IndividualDetailsPageState
501500
final options =
502501
appConfiguration.genderOptions ?? <GenderOptions>[];
503502

504-
return options
505-
.map((e) => localizations.translate(e.name))
506-
.firstWhereOrNull(
507-
(element) => element == individual?.gender?.name,
503+
return options.map((e) => e.code).firstWhereOrNull(
504+
(element) =>
505+
element.toLowerCase() == individual?.gender?.name,
508506
);
509507
},
510508
),

apps/health_campaign_field_worker_app/lib/pages/boundary_selection.dart

Lines changed: 96 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:collection/collection.dart';
33
import 'package:digit_components/digit_components.dart';
44
import 'package:flutter/material.dart';
55
import 'package:flutter_bloc/flutter_bloc.dart';
6+
import 'package:reactive_forms/reactive_forms.dart';
67

78
import '../blocs/boundary/boundary.dart';
89
import '../models/data_model.dart';
@@ -16,6 +17,7 @@ class BoundarySelectionPage extends StatefulWidget {
1617

1718
class _BoundarySelectionPageState extends State<BoundarySelectionPage> {
1819
bool shouldPop = false;
20+
static const _selectedBoundaryKey = 'boundary';
1921

2022
@override
2123
Widget build(BuildContext context) {
@@ -37,90 +39,95 @@ class _BoundarySelectionPageState extends State<BoundarySelectionPage> {
3739

3840
final labelList = state.selectedBoundaryMap.keys.toList();
3941

40-
return Column(
41-
children: [
42-
Expanded(
43-
child: ListView.builder(
44-
itemCount: labelList.length,
45-
itemBuilder: (context, labelIndex) {
46-
final label = labelList.elementAt(labelIndex);
47-
48-
final filteredItems =
49-
state.boundaryList.where((element) {
50-
if (element.label != label) return false;
51-
52-
if (labelIndex == 0) return true;
53-
final parentIndex = labelIndex - 1;
54-
55-
final parentBoundaryEntry = state
56-
.selectedBoundaryMap.entries
57-
.elementAtOrNull(parentIndex);
58-
final parentBoundary = parentBoundaryEntry?.value;
59-
if (parentBoundary == null) return false;
60-
61-
if (element.materializedPathList
62-
.contains(parentBoundary.code)) {
63-
return true;
64-
}
65-
66-
return false;
67-
}).toList();
68-
69-
return Padding(
70-
padding: const EdgeInsets.symmetric(
71-
horizontal: kPadding * 2,
72-
),
73-
child: DigitDropdown<BoundaryModel>(
74-
value: state.selectedBoundaryMap.entries
75-
.firstWhereOrNull(
76-
(element) => element.key == label,
77-
)
78-
?.value,
79-
label: label,
80-
menuItems: filteredItems,
81-
onChanged: (value) {
82-
if (value == null) return;
83-
84-
context.read<BoundaryBloc>().add(
85-
BoundarySelectEvent(
86-
label: label,
87-
selectedBoundary: value,
88-
),
89-
);
90-
},
91-
valueMapper: (value) {
92-
return value.name ?? value.code ?? 'No Value';
93-
},
94-
),
95-
);
96-
},
97-
),
98-
),
99-
DigitCard(
100-
margin: const EdgeInsets.only(left: 0, right: 0, top: 10),
101-
child: SafeArea(
102-
child: DigitElevatedButton(
103-
onPressed: selectedBoundary == null
104-
? null
105-
: () async {
106-
setState(() {
107-
shouldPop = true;
108-
});
42+
return ReactiveFormBuilder(
43+
form: () => buildForm(),
44+
builder: (context, form, child) => Column(
45+
children: [
46+
Expanded(
47+
child: ListView.builder(
48+
itemCount: labelList.length,
49+
itemBuilder: (context, labelIndex) {
50+
final label = labelList.elementAt(labelIndex);
51+
52+
final filteredItems =
53+
state.boundaryList.where((element) {
54+
if (element.label != label) return false;
55+
56+
if (labelIndex == 0) return true;
57+
final parentIndex = labelIndex - 1;
58+
59+
final parentBoundaryEntry = state
60+
.selectedBoundaryMap.entries
61+
.elementAtOrNull(parentIndex);
62+
final parentBoundary = parentBoundaryEntry?.value;
63+
if (parentBoundary == null) return false;
64+
65+
if (element.materializedPathList
66+
.contains(parentBoundary.code)) {
67+
return true;
68+
}
69+
70+
return false;
71+
}).toList();
72+
73+
return Padding(
74+
padding: const EdgeInsets.symmetric(
75+
horizontal: kPadding * 2,
76+
),
77+
child: DigitDropdown<BoundaryModel>(
78+
initialValue: state.selectedBoundaryMap.entries
79+
.firstWhereOrNull(
80+
(element) => element.key == label,
81+
)
82+
?.value,
83+
label: label,
84+
menuItems: filteredItems,
85+
onChanged: (value) {
86+
if (value == null) return;
10987

11088
context.read<BoundaryBloc>().add(
111-
const BoundarySubmitEvent(),
89+
BoundarySelectEvent(
90+
label: label,
91+
selectedBoundary: value,
92+
),
11293
);
113-
114-
Future.delayed(
115-
const Duration(milliseconds: 100),
116-
() => context.router.pop(),
117-
);
11894
},
119-
child: const Text('Submit'),
95+
valueMapper: (value) {
96+
return value.name ?? value.code ?? 'No Value';
97+
},
98+
formControlName: _selectedBoundaryKey,
99+
),
100+
);
101+
},
102+
),
103+
),
104+
DigitCard(
105+
margin:
106+
const EdgeInsets.only(left: 0, right: 0, top: 10),
107+
child: SafeArea(
108+
child: DigitElevatedButton(
109+
onPressed: selectedBoundary == null
110+
? null
111+
: () async {
112+
setState(() {
113+
shouldPop = true;
114+
});
115+
116+
context.read<BoundaryBloc>().add(
117+
const BoundarySubmitEvent(),
118+
);
119+
120+
Future.delayed(
121+
const Duration(milliseconds: 100),
122+
() => context.router.pop(),
123+
);
124+
},
125+
child: const Text('Submit'),
126+
),
120127
),
121128
),
122-
),
123-
],
129+
],
130+
),
124131
);
125132
},
126133
),
@@ -129,4 +136,15 @@ class _BoundarySelectionPageState extends State<BoundarySelectionPage> {
129136
),
130137
);
131138
}
139+
140+
FormGroup buildForm() {
141+
return fb.group(<String, Object>{
142+
_selectedBoundaryKey: FormControl<BoundaryModel>(
143+
validators: [
144+
Validators.required,
145+
],
146+
value: null,
147+
),
148+
});
149+
}
132150
}

apps/health_campaign_field_worker_app/lib/pages/login.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ class _LoginPageState extends LocalizedState<LoginPage> {
187187

188188
FormGroup buildForm() => fb.group(<String, Object>{
189189
_userId: FormControl<String>(
190-
value: '',
190+
value: 'distNihAP1',
191191
validators: [Validators.required],
192192
),
193193
_password: FormControl<String>(
194194
validators: [Validators.required],
195-
value: '',
195+
value: 'eGov@1234',
196196
),
197197
});
198198
}

packages/digit_components/lib/widgets/atoms/digit_dropdown.dart

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import 'package:flutter/material.dart';
2+
import 'package:reactive_forms/reactive_forms.dart';
23

34
class DigitDropdown<T> extends StatelessWidget {
45
final String label;
5-
final T? value;
6+
final T? initialValue;
67
final List<T> menuItems;
8+
final String formControlName;
79
final bool isRequired;
8-
final ValueChanged<T?>? onChanged;
10+
final ValueChanged<T>? onChanged;
911
final String Function(T value) valueMapper;
12+
final Map<String, String Function(Object object)>? validationMessages;
1013

1114
const DigitDropdown({
1215
super.key,
13-
required this.value,
1416
required this.label,
1517
required this.menuItems,
18+
required this.formControlName,
1619
this.isRequired = false,
1720
required this.valueMapper,
21+
this.initialValue,
1822
this.onChanged,
23+
this.validationMessages,
1924
});
2025

2126
@override
@@ -30,9 +35,14 @@ class DigitDropdown<T> extends StatelessWidget {
3035
style: Theme.of(context).textTheme.bodyLarge,
3136
),
3237
const SizedBox(height: 8),
33-
DropdownButtonFormField<T>(
34-
value: value,
35-
onChanged: onChanged,
38+
ReactiveDropdownField(
39+
onChanged: (control) {
40+
final value = control.value;
41+
if (value == null) return;
42+
onChanged?.call(value);
43+
},
44+
validationMessages: validationMessages,
45+
formControlName: formControlName,
3646
decoration: const InputDecoration(
3747
contentPadding: EdgeInsets.fromLTRB(16, 12, 0, 12),
3848
),
@@ -50,3 +60,13 @@ class DigitDropdown<T> extends StatelessWidget {
5060
);
5161
}
5262
}
63+
64+
class MenuItemModel {
65+
final String name;
66+
final String code;
67+
68+
const MenuItemModel({
69+
required this.name,
70+
required this.code,
71+
});
72+
}

packages/digit_components/lib/widgets/atoms/digit_reactive_dropdown.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,3 @@ class DigitReactiveDropdown<T> extends StatelessWidget {
7272
}
7373
}
7474

75-
class MenuItemModel {
76-
final String name;
77-
final String code;
78-
79-
const MenuItemModel({
80-
required this.name,
81-
required this.code,
82-
});
83-
}

0 commit comments

Comments
 (0)