feat : dynamic form navigation

This commit is contained in:
2025-04-26 16:50:19 +03:30
parent 6e6d2b22f6
commit c10ddaf0d5
11 changed files with 568 additions and 369 deletions

View File

@@ -26,22 +26,22 @@ class AddMobileInspectorPage extends GetView<AddMobileInspectorLogic> {
RFab.smallAdd(onPressed: () => controller.countInspector.value++),
],
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
child: Column(
body: Column(
children: [
Expanded(
child: ObxValue((data) {
return ListView.separated(
padding: const EdgeInsets.fromLTRB(25, 10, 25, 0),
itemBuilder:
(context, index) => Container(
(context, index) =>
Container(
padding: EdgeInsets.symmetric(
horizontal: 12,
vertical: 16,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
border: Border.all(width: 1, color: AppColor.bgDark),
border: Border.all(width: 0.7, color: AppColor.bgDark),
),
child: Column(
spacing: 16,
@@ -81,12 +81,14 @@ class AddMobileInspectorPage extends GetView<AddMobileInspectorLogic> {
Expanded(
child: RElevated(
text: 'ثبت',
textStyle:AppFonts.yekan16.copyWith(color: Colors.white),
onPressed: () {},
),
),
Expanded(
child: ROutlinedElevated(
text: 'انصراف',
textStyle:AppFonts.yekan16,
onPressed: () {},
),
),
@@ -103,19 +105,21 @@ class AddMobileInspectorPage extends GetView<AddMobileInspectorLogic> {
}, controller.countInspector),
),
RElevated(
Padding(
padding: const EdgeInsets.fromLTRB(20, 4, 20, 20),
child: RElevated(
text: 'مرحله بعد',
onPressed: () {
Get.toNamed(InspectionRoutes.inspectionRegistrationOfViolation);
},
height: 50,
isFullWidth: true,
height: 40,
backgroundColor: AppColor.greenNormal,
textStyle: AppFonts.yekan16.copyWith(color: Colors.white),
),
SizedBox(height: 25),
],
),
],
),
);
}

View File

@@ -1,11 +1,19 @@
import 'package:flutter/material.dart';
import 'package:inspection/presentation/routes/app_routes.dart';
import 'package:rasadyar_core/core.dart';
class AddSupervisionLogic extends GetxController {
RxInt selectedSegment = 0.obs;
RxInt violationSegmentsSelected = 0.obs;
RxInt selectedTypeOfOwnership = 0.obs;
RxInt selectedUnitType = 0.obs;
RxInt selectedAccompanyingInspectors = 0.obs;
RxList<int> selectedAccompanyingInspectors = RxList<int>([0]);
Map<String,List<String>> tmpData = {
'نوع مالکیت': ['دولتی', 'غیر دولتی', 'استیجاری', 'شخصی', 'سایر'],
'نوع واحد': ['دولتی', 'غیر دولتی', 'استیجاری', 'شخصی', 'سایر'],
'بازرسان همراه': ['ندارد','دولتی', 'غیر دولتی', 'استیجاری', 'شخصی', 'سایر'],
};
List<String> tmpLs = ['دولتی', 'غیر دولتی', 'استیجاری', 'شخصی', 'سایر'];
@@ -23,10 +31,34 @@ class AddSupervisionLogic extends GetxController {
),
};
// The data for the segments
final Map<int, Widget> violationSegments = {
0: Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(50)),
child: Text('دارد', style: AppFonts.yekan13),
),
1: Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(50)),
child: Text('ندارد', style: AppFonts.yekan13),
),
};
List<String> routes = [
InspectionRoutes.inspectionRegistrationOfViolation,
InspectionRoutes.inspectionDisplayInformation
];
@override
void onReady() {
// TODO: implement onReady
super.onReady();
}
@override

View File

@@ -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,16 +20,22 @@ class AddSupervisionPage extends GetView<AddSupervisionLogic> {
height: 16,
),
),
body: SingleChildScrollView(
child: Column(
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 16,
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 10,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 12,
children: [
Text(
'نوع پروانه کسب',
@@ -41,7 +44,7 @@ class AddSupervisionPage extends GetView<AddSupervisionLogic> {
color: AppColor.blueNormal,
),
),
SizedBox(height: 16),
ObxValue((data) {
return NewCupertinoSegmentedControl<int>(
padding: EdgeInsets.zero,
@@ -55,26 +58,92 @@ class AddSupervisionPage extends GetView<AddSupervisionLogic> {
},
);
}, 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: 'کد اقتصادی'),
],
),
),
optionWidget(controller.selectedTypeOfOwnership),
optionWidget(controller.selectedAccompanyingInspectors),
optionWidget(controller.selectedUnitType),
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;
if (data == 0) {
selected.resetWith(0);
controller.routes.remove(route);
return;
}
controller.routes.ensureContainsAtStart(route);
selected.removeIfPresent(0);
selected.toggle(data);
},
),
],
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
child: RElevated(
text: 'مرحله بعد',
onPressed: () {
Get.toNamed(InspectionRoutes.inspectionAddMobileInspector);
Get.toNamed(controller.routes.first);
},
height: 40,
height: 50,
isFullWidth: true,
backgroundColor: AppColor.greenNormal,
textStyle: AppFonts.yekan16.copyWith(color: Colors.white),
@@ -82,36 +151,51 @@ class AddSupervisionPage extends GetView<AddSupervisionLogic> {
),
],
),
),
);
}
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) {
(context, index) =>
selected != null
? ObxValue((data) {
return ChoiceChip(
onSelected: (value) {
selected.value = index;
},
selectedColor: AppColor.blueNormal,
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(
@@ -121,13 +205,36 @@ class AddSupervisionPage extends GetView<AddSupervisionLogic> {
color: AppColor.darkGreyNormalActive,
),
checkmarkColor: Colors.white,
label: Text(controller.tmpLs[index]),
label: Text(options.value[index]),
selected: index == data.value,
);
}, selected),
}, 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,
),
),
],

View File

@@ -80,7 +80,18 @@ class LocationDetailsPage extends GetView<LocationDetailsLogic> {
Expanded(
child: ROutlinedElevatedIcon(
icon: FaIcon(FontAwesomeIcons.calendar),
onPressed: () {},
onPressed: () async {
Jalali? picked = await showPersianDatePicker(
context: context,
initialDate: Jalali.now(),
firstDate: Jalali(1385, 8),
lastDate: Jalali(1450, 9),
initialEntryMode:
PersianDatePickerEntryMode.calendarOnly,
initialDatePickerMode: PersianDatePickerMode.day,
);
var label = picked?.formatFullDate();
},
text: 'تا تاریخ',
textStyle: AppFonts.yekan16.copyWith(
color: AppColor.blueNormal,
@@ -140,7 +151,7 @@ class LocationDetailsPage extends GetView<LocationDetailsLogic> {
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 22,
vertical: 25,
vertical: 21,
),
child: Column(
spacing: 6,
@@ -154,7 +165,7 @@ class LocationDetailsPage extends GetView<LocationDetailsLogic> {
),
SizedBox(height: 2),
Text(
'1043/12/12',
'1403/12/12',
textAlign: TextAlign.center,
style: AppFonts.yekan12,
),

View File

@@ -1,10 +1,8 @@
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/buttons/fab.dart';
import 'package:rasadyar_core/presentation/widget/inputs/r_input.dart';
import 'package:inspection/presentation/registration_of_violation/logic.dart';
import 'package:inspection/presentation/routes/app_routes.dart';
import 'package:rasadyar_core/core.dart';
import 'package:rasadyar_core/presentation/widget/buttons/fab.dart';
class RegistrationOfViolationPage
extends GetView<RegistrationOfViolationLogic> {
@@ -33,50 +31,48 @@ backgroundColor:AppColor.bgLight,
Expanded(
child: ObxValue((data) {
return ListView.separated(
itemBuilder: (context, index) =>Container(
padding:EdgeInsets.symmetric(horizontal: 8,vertical: 12),
itemBuilder:
(context, index) => Container(
padding: EdgeInsets.symmetric(
horizontal: 8,
vertical: 12,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
border: Border.all(width: 1,color: AppColor.bgDark),
border: Border.all(width: 0.75, color: AppColor.bgDark),
),
child: Column(
spacing: 16,
children: [
RTextField(
label: 'عنوان تخلف',
filled: true,
filledColor: AppColor.whiteLight,
),
RTextField(
label: 'توضیحات تخلف',
filled: true,
filledColor: AppColor.whiteLight,
maxLines: 5,
minLines: 5,
maxLines: 3,
minLines: 3,
),
RTextField(
label: 'عنوان تخلف',
filled: true,
filledColor: AppColor.whiteLight,
),
RTextField(
label: 'عنوان تخلف',
filled: true,
filledColor: AppColor.whiteLight,
),
RTextField(
label: 'توضیحات تخلف',
filled: true,
filledColor: AppColor.whiteLight,
maxLines: 5,
minLines: 5,
maxLines: 3,
minLines: 3,
),
SizedBox(
@@ -84,17 +80,25 @@ backgroundColor:AppColor.bgLight,
child: Row(
spacing: 16,
children: [
Expanded(child: RElevated(text: 'ثبت', onPressed: (){})),
Expanded(child:ROutlinedElevated(text: 'انصراف',onPressed: (){},) ),
],
Expanded(
child: RElevated(
text: 'ثبت',
onPressed: () {},
),
),
Expanded(
child: ROutlinedElevated(
text: 'انصراف',
onPressed: () {},
),
),
)
],
),
),
separatorBuilder: (context, index) => SizedBox(height: 15,),
],
),
),
separatorBuilder: (context, index) => SizedBox(height: 15),
itemCount: data.value,
);
}, controller.countViolation),
@@ -110,7 +114,7 @@ backgroundColor:AppColor.bgLight,
backgroundColor: AppColor.greenNormal,
textStyle: AppFonts.yekan16.copyWith(color: Colors.white),
),
SizedBox(height: 25,)
SizedBox(height: 25),
],
),
),

View File

@@ -1,4 +1,3 @@
import 'package:device_preview/device_preview.dart';
import 'package:flutter/material.dart';
import 'package:rasadyar_app/domain/service/user/user_service.dart';
import 'package:rasadyar_app/presentation/routes/app_pages.dart';
@@ -15,8 +14,6 @@ void main() async {
// runApp(DevicePreview(builder: (context) => ForDevicePreview(),));
}
/*class ForDevicePreview extends StatelessWidget {
const ForDevicePreview({super.key});
@@ -51,6 +48,10 @@ class MyApp extends StatelessWidget {
initialBinding: BindingsBuilder.put(() => UserService()),
getPages: AppPages.pages,
locale: Locale('fa'),
localizationsDelegates: [
PersianMaterialLocalizations.delegate,
PersianCupertinoLocalizations.delegate,
],
);
}
}

View File

@@ -9,5 +9,5 @@ export 'package:rasadyar_core/presentation/widget/widget.dart';
export 'package:flutter_slidable/flutter_slidable.dart';
export 'package:font_awesome_flutter/font_awesome_flutter.dart';
export 'package:flutter_rating_bar/flutter_rating_bar.dart';
export 'package:persian_datetime_picker/persian_datetime_picker.dart';
import 'package:dartx/dartx.dart' as dartx;

View File

@@ -0,0 +1,26 @@
extension ListExtensions<T> on List<T> {
void toggle(T item) {
if (contains(item)) {
if (length > 1) {
remove(item);
}
} else {
add(item);
}
}
void ensureContainsAtStart(T item) {
if (!contains(item)) {
insert(0, item);
}
}
void removeIfPresent(T item) {
remove(item);
}
void resetWith(T item) {
clear();
add(item);
}
}

View File

@@ -1 +1,2 @@
export 'color_utils.dart';
export 'list_extensions.dart';

View File

@@ -43,7 +43,7 @@ class _ROutlinedElevatedStateIcon extends State<ROutlinedElevatedIcon> {
return OutlinedButton.icon(
icon: widget.icon,
label: Text(widget.text),
onPressed: () {},
onPressed: widget.onPressed,
style: ButtonStyle(
side: WidgetStateProperty.resolveWith<BorderSide?>((states) {
if (states.contains(WidgetState.pressed)) {

View File

@@ -1,12 +1,11 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart';
@immutable
class RTextField extends StatefulWidget {
RTextField(
{super.key,
RTextField({
super.key,
this.maxLines,
this.maxLength,
this.hintText,
@@ -32,16 +31,18 @@ class RTextField extends StatefulWidget {
this.enabled,
this.errorStyle,
this.labelStyle,
this.label}) {
this.label,
}) {
filled = filled ?? false;
obscure = false;
_inputBorder = OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade300),
borderRadius: BorderRadius.circular(radius ?? 16));
borderRadius: BorderRadius.circular(radius ?? 8),
);
}
RTextField.noBorder(
{super.key,
RTextField.noBorder({
super.key,
this.maxLines,
this.maxLength,
this.hintText,
@@ -66,16 +67,18 @@ class RTextField extends StatefulWidget {
this.filledColor,
this.errorStyle,
this.labelStyle,
this.enabled}) {
this.enabled,
}) {
_inputBorder = OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(radius ?? 16));
borderRadius: BorderRadius.circular(radius ?? 16),
);
obscure = false;
filled = filled ?? true;
}
RTextField.password(
{super.key,
RTextField.password({
super.key,
this.maxLines = 1,
this.maxLength,
this.hintText,
@@ -101,10 +104,12 @@ class RTextField extends StatefulWidget {
this.filledColor,
this.errorStyle,
this.labelStyle,
this.enabled}) {
this.enabled,
}) {
_inputBorder = OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(radius ?? 16));
borderRadius: BorderRadius.circular(radius ?? 16),
);
filled = filled ?? true;
obscure = true;
_isPassword = true;
@@ -170,7 +175,7 @@ class _RTextFieldState extends State<RTextField> {
@override
Widget build(BuildContext context) {
return Padding(
padding: widget.padding ?? const EdgeInsets.symmetric(vertical: 6.0),
padding: widget.padding ?? EdgeInsets.zero,
child: TextFormField(
controller: _controller,
readOnly: widget.readonly,
@@ -189,10 +194,12 @@ class _RTextFieldState extends State<RTextField> {
style: widget.style,
keyboardType: widget.keyboardType,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(horizontal: 16),
errorStyle: widget.errorStyle,
errorMaxLines: 1,
isDense: widget.isDense,
suffixIcon: widget.suffixIcon ??
suffixIcon:
widget.suffixIcon ??
(widget._isPassword
? IconButton(
onPressed: () {
@@ -200,23 +207,29 @@ class _RTextFieldState extends State<RTextField> {
obscure = !obscure!;
});
},
icon: Icon(!obscure!
? CupertinoIcons.eye_slash
: CupertinoIcons.eye))
icon: Icon(
!obscure! ? CupertinoIcons.eye_slash : CupertinoIcons.eye,
),
)
: null),
suffixIconConstraints: widget.boxConstraints,
prefixIcon: widget.prefixIcon,
prefixIconConstraints: widget.boxConstraints,
hintText: widget.hintText,
labelText: widget.label,
labelStyle: widget.labelStyle??AppFonts.yekan14.copyWith(color: AppColor.lightGreyDarkActive),
alignLabelWithHint: true,
labelStyle: AppFonts.yekan14
.copyWith(color: AppColor.lightGreyDarkActive)
.merge(widget.labelStyle),
filled: widget.filled,
fillColor: widget.filledColor,
counter: widget.showCounter ? null : const SizedBox(),
hintStyle: widget.hintStyle,
enabledBorder: widget._inputBorder,
focusedBorder: widget._inputBorder,
border: widget._inputBorder),
));
border: widget._inputBorder,
),
),
);
}
}