feat : dynamic form navigation
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_core/presentation/widget/buttons/elevated.dart';
|
||||
import 'package:rasadyar_core/presentation/widget/inputs/r_input.dart';
|
||||
import 'package:rasadyar_core/presentation/widget/tabs/new_tab.dart';
|
||||
import 'package:inspection/inspection.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
import 'logic.dart';
|
||||
|
||||
@@ -23,111 +20,221 @@ class AddSupervisionPage extends GetView<AddSupervisionLogic> {
|
||||
height: 16,
|
||||
),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 16,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
children: [
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 12,
|
||||
children: [
|
||||
Text(
|
||||
'نوع پروانه کسب',
|
||||
textAlign: TextAlign.center,
|
||||
style: AppFonts.yekan12.copyWith(
|
||||
color: AppColor.blueNormal,
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 10,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
children: [
|
||||
Text(
|
||||
'نوع پروانه کسب',
|
||||
textAlign: TextAlign.center,
|
||||
style: AppFonts.yekan12.copyWith(
|
||||
color: AppColor.blueNormal,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
ObxValue((data) {
|
||||
return NewCupertinoSegmentedControl<int>(
|
||||
padding: EdgeInsets.zero,
|
||||
children: controller.segments,
|
||||
groupValue: data.value,
|
||||
selectedColor: AppColor.blueNormal,
|
||||
unselectedColor: Colors.white,
|
||||
borderColor: Colors.grey.shade300,
|
||||
onValueChanged: (int value) {
|
||||
data.value = value;
|
||||
},
|
||||
);
|
||||
}, controller.selectedSegment),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'تخلف',
|
||||
textAlign: TextAlign.center,
|
||||
style: AppFonts.yekan12.copyWith(
|
||||
color: AppColor.blueNormal,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
ObxValue((data) {
|
||||
return NewCupertinoSegmentedControl<int>(
|
||||
padding: EdgeInsets.zero,
|
||||
children: controller.violationSegments,
|
||||
groupValue: data.value,
|
||||
selectedColor: AppColor.blueNormal,
|
||||
unselectedColor: Colors.white,
|
||||
borderColor: Colors.grey.shade300,
|
||||
onValueChanged: (int value) {
|
||||
if(value == 0) {
|
||||
controller.routes.ensureContainsAtStart(InspectionRoutes.inspectionRegistrationOfViolation);
|
||||
} else {
|
||||
controller.routes.remove(InspectionRoutes.inspectionRegistrationOfViolation);
|
||||
}
|
||||
data.value = value;
|
||||
},
|
||||
);
|
||||
}, controller.violationSegmentsSelected),
|
||||
SizedBox(height: 8),
|
||||
RTextField(label: 'صادر کننده پروانه'),
|
||||
SizedBox(height: 8),
|
||||
RTextField(label: 'شماره مجوز'),
|
||||
SizedBox(height: 8),
|
||||
RTextField(label: 'شماره ثبت'),
|
||||
SizedBox(height: 8),
|
||||
RTextField(label: 'کد اقتصادی'),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
optionWidget(
|
||||
selected: controller.selectedTypeOfOwnership,
|
||||
options: controller.tmpData.entries.elementAt(0),
|
||||
onSelected:
|
||||
(index) =>
|
||||
controller.selectedTypeOfOwnership.value = index,
|
||||
),
|
||||
SizedBox(height: 18),
|
||||
optionWidget(
|
||||
selected: controller.selectedUnitType,
|
||||
options: controller.tmpData.entries.elementAt(1),
|
||||
onSelected:
|
||||
(index) => controller.selectedUnitType.value = index,
|
||||
),
|
||||
SizedBox(height: 18),
|
||||
optionWidget(
|
||||
selectedList: controller.selectedAccompanyingInspectors,
|
||||
options: controller.tmpData.entries.elementAt(2),
|
||||
onSelected: (data) {
|
||||
final selected = controller.selectedAccompanyingInspectors;
|
||||
final route = InspectionRoutes.inspectionAddMobileInspector;
|
||||
|
||||
ObxValue((data) {
|
||||
return NewCupertinoSegmentedControl<int>(
|
||||
padding: EdgeInsets.zero,
|
||||
children: controller.segments,
|
||||
groupValue: data.value,
|
||||
selectedColor: AppColor.blueNormal,
|
||||
unselectedColor: Colors.white,
|
||||
borderColor: Colors.grey.shade300,
|
||||
onValueChanged: (int value) {
|
||||
data.value = value;
|
||||
},
|
||||
);
|
||||
}, controller.selectedSegment),
|
||||
if (data == 0) {
|
||||
selected.resetWith(0);
|
||||
controller.routes.remove(route);
|
||||
return;
|
||||
}
|
||||
|
||||
RTextField(label: 'صادر کننده پروانه'),
|
||||
RTextField(label: 'شماره مجوز'),
|
||||
RTextField(label: 'شماره ثبت'),
|
||||
RTextField(label: 'کد اقتصادی'),
|
||||
controller.routes.ensureContainsAtStart(route);
|
||||
selected.removeIfPresent(0);
|
||||
selected.toggle(data);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
optionWidget(controller.selectedTypeOfOwnership),
|
||||
optionWidget(controller.selectedAccompanyingInspectors),
|
||||
optionWidget(controller.selectedUnitType),
|
||||
),
|
||||
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: RElevated(
|
||||
text: 'مرحله بعد',
|
||||
onPressed: () {
|
||||
Get.toNamed(InspectionRoutes.inspectionAddMobileInspector);
|
||||
},
|
||||
height: 40,
|
||||
isFullWidth: true,
|
||||
backgroundColor: AppColor.greenNormal,
|
||||
textStyle: AppFonts.yekan16.copyWith(color: Colors.white),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
|
||||
child: RElevated(
|
||||
text: 'مرحله بعد',
|
||||
onPressed: () {
|
||||
Get.toNamed(controller.routes.first);
|
||||
|
||||
},
|
||||
height: 50,
|
||||
isFullWidth: true,
|
||||
backgroundColor: AppColor.greenNormal,
|
||||
textStyle: AppFonts.yekan16.copyWith(color: Colors.white),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Column optionWidget(RxInt selected) {
|
||||
Column optionWidget({
|
||||
RxInt? selected,
|
||||
RxList<int>? selectedList,
|
||||
required MapEntry<String, List<String>> options,
|
||||
required void Function(int index) onSelected,
|
||||
}) {
|
||||
assert(
|
||||
(selected != null) != (selectedList != null),
|
||||
'Exactly one of selected or selectedList must be provided',
|
||||
);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Text(
|
||||
'نوع پروانه کسب',
|
||||
options.key,
|
||||
textAlign: TextAlign.center,
|
||||
style: AppFonts.yekan12.copyWith(color: AppColor.blueNormal),
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(
|
||||
height: 75,
|
||||
height: 50,
|
||||
child: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.all(20),
|
||||
padding: EdgeInsets.symmetric(horizontal: 20),
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemBuilder:
|
||||
(context, index) => ObxValue((data) {
|
||||
return ChoiceChip(
|
||||
onSelected: (value) {
|
||||
selected.value = index;
|
||||
},
|
||||
selectedColor: AppColor.blueNormal,
|
||||
labelStyle:
|
||||
data.value == index
|
||||
? AppFonts.yekan13.copyWith(
|
||||
color: AppColor.whiteLight,
|
||||
)
|
||||
: AppFonts.yekan12.copyWith(
|
||||
color: AppColor.darkGreyNormalActive,
|
||||
),
|
||||
checkmarkColor: Colors.white,
|
||||
label: Text(controller.tmpLs[index]),
|
||||
selected: index == data.value,
|
||||
);
|
||||
}, selected),
|
||||
(context, index) =>
|
||||
selected != null
|
||||
? ObxValue((data) {
|
||||
return ChoiceChip(
|
||||
onSelected: (_) => onSelected(index),
|
||||
color: WidgetStateProperty.resolveWith<Color?>((data,) {
|
||||
if (selected.value == index) {
|
||||
return AppColor.blueNormal;
|
||||
} else {
|
||||
return Colors.white;
|
||||
}
|
||||
}),
|
||||
labelStyle:
|
||||
data.value == index
|
||||
? AppFonts.yekan13.copyWith(
|
||||
color: AppColor.whiteLight,
|
||||
)
|
||||
: AppFonts.yekan12.copyWith(
|
||||
color: AppColor.darkGreyNormalActive,
|
||||
),
|
||||
checkmarkColor: Colors.white,
|
||||
label: Text(options.value[index]),
|
||||
selected: index == data.value,
|
||||
);
|
||||
}, selected)
|
||||
: ObxValue((data) {
|
||||
return ChoiceChip(
|
||||
onSelected: (value) => onSelected.call(index),
|
||||
color: WidgetStateProperty.resolveWith<Color?>((states,) {
|
||||
if (data.contains(index)) {
|
||||
return AppColor.blueNormal;
|
||||
} else {
|
||||
return Colors.white;
|
||||
}
|
||||
}),
|
||||
labelStyle:
|
||||
data.contains(index)
|
||||
? AppFonts.yekan13.copyWith(
|
||||
color: AppColor.whiteLight,
|
||||
)
|
||||
: AppFonts.yekan12.copyWith(
|
||||
color: AppColor.darkGreyNormalActive,
|
||||
),
|
||||
checkmarkColor: Colors.white,
|
||||
label: Text(options.value[index]),
|
||||
selected: data.contains(index),
|
||||
);
|
||||
}, selectedList!),
|
||||
|
||||
separatorBuilder: (context, index) => SizedBox(width: 8),
|
||||
itemCount: controller.tmpLs.length,
|
||||
itemCount: options.value.length,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user