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,96 +26,100 @@ class AddMobileInspectorPage extends GetView<AddMobileInspectorLogic> {
RFab.smallAdd(onPressed: () => controller.countInspector.value++), RFab.smallAdd(onPressed: () => controller.countInspector.value++),
], ],
), ),
body: Padding( body: Column(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10), children: [
child: Column( Expanded(
children: [ child: ObxValue((data) {
Expanded( return ListView.separated(
child: ObxValue((data) { padding: const EdgeInsets.fromLTRB(25, 10, 25, 0),
return ListView.separated( itemBuilder:
itemBuilder: (context, index) =>
(context, index) => Container( Container(
padding: EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
horizontal: 12, horizontal: 12,
vertical: 16, vertical: 16,
), ),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
border: Border.all(width: 1, color: AppColor.bgDark), border: Border.all(width: 0.7, color: AppColor.bgDark),
), ),
child: Column( child: Column(
spacing: 16, spacing: 16,
children: [ children: [
RTextField( RTextField(
label: 'نام و نام خانوادگی', label: 'نام و نام خانوادگی',
filled: true, filled: true,
filledColor: AppColor.whiteLight, filledColor: AppColor.whiteLight,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
), ),
RTextField( RTextField(
label: 'شماره مجوز', label: 'شماره مجوز',
filled: true, filled: true,
filledColor: AppColor.whiteLight, filledColor: AppColor.whiteLight,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
), ),
RTextField( RTextField(
label: 'شماره ثبت', label: 'شماره ثبت',
filled: true, filled: true,
filledColor: AppColor.whiteLight, filledColor: AppColor.whiteLight,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
), ),
RTextField( RTextField(
label: 'کد اقتصادی', label: 'کد اقتصادی',
filled: true, filled: true,
filledColor: AppColor.whiteLight, filledColor: AppColor.whiteLight,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
), ),
Padding( Padding(
padding: const EdgeInsets.symmetric(vertical: 12), padding: const EdgeInsets.symmetric(vertical: 12),
child: SizedBox( child: SizedBox(
height: 40, height: 40,
child: Row( child: Row(
spacing: 16, spacing: 16,
children: [ children: [
Expanded( Expanded(
child: RElevated( child: RElevated(
text: 'ثبت', text: 'ثبت',
onPressed: () {}, textStyle:AppFonts.yekan16.copyWith(color: Colors.white),
), onPressed: () {},
), ),
Expanded( ),
child: ROutlinedElevated( Expanded(
text: 'انصراف', child: ROutlinedElevated(
onPressed: () {}, text: 'انصراف',
), textStyle:AppFonts.yekan16,
onPressed: () {},
), ),
], ),
), ],
), ),
), ),
], ),
), ],
), ),
separatorBuilder: (context, index) => SizedBox(height: 15), ),
itemCount: data.value, separatorBuilder: (context, index) => SizedBox(height: 15),
); itemCount: data.value,
}, controller.countInspector), );
), }, controller.countInspector),
),
RElevated(
Padding(
padding: const EdgeInsets.fromLTRB(20, 4, 20, 20),
child: RElevated(
text: 'مرحله بعد', text: 'مرحله بعد',
onPressed: () { onPressed: () {
Get.toNamed(InspectionRoutes.inspectionRegistrationOfViolation); Get.toNamed(InspectionRoutes.inspectionRegistrationOfViolation);
}, },
height: 50,
isFullWidth: true, isFullWidth: true,
height: 40,
backgroundColor: AppColor.greenNormal, backgroundColor: AppColor.greenNormal,
textStyle: AppFonts.yekan16.copyWith(color: Colors.white), textStyle: AppFonts.yekan16.copyWith(color: Colors.white),
), ),
SizedBox(height: 25), ),
], ],
),
), ),
); );
} }

View File

@@ -1,11 +1,19 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:inspection/presentation/routes/app_routes.dart';
import 'package:rasadyar_core/core.dart'; import 'package:rasadyar_core/core.dart';
class AddSupervisionLogic extends GetxController { class AddSupervisionLogic extends GetxController {
RxInt selectedSegment = 0.obs; RxInt selectedSegment = 0.obs;
RxInt violationSegmentsSelected = 0.obs;
RxInt selectedTypeOfOwnership = 0.obs; RxInt selectedTypeOfOwnership = 0.obs;
RxInt selectedUnitType = 0.obs; RxInt selectedUnitType = 0.obs;
RxInt selectedAccompanyingInspectors = 0.obs; RxList<int> selectedAccompanyingInspectors = RxList<int>([0]);
Map<String,List<String>> tmpData = {
'نوع مالکیت': ['دولتی', 'غیر دولتی', 'استیجاری', 'شخصی', 'سایر'],
'نوع واحد': ['دولتی', 'غیر دولتی', 'استیجاری', 'شخصی', 'سایر'],
'بازرسان همراه': ['ندارد','دولتی', 'غیر دولتی', 'استیجاری', 'شخصی', 'سایر'],
};
List<String> tmpLs = ['دولتی', 'غیر دولتی', 'استیجاری', 'شخصی', 'سایر']; 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 @override
void onReady() { void onReady() {
// TODO: implement onReady
super.onReady(); super.onReady();
} }
@override @override

View File

@@ -1,9 +1,6 @@
import 'package:flutter/material.dart'; 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:inspection/inspection.dart';
import 'package:rasadyar_core/core.dart';
import 'logic.dart'; import 'logic.dart';
@@ -23,111 +20,221 @@ class AddSupervisionPage extends GetView<AddSupervisionLogic> {
height: 16, height: 16,
), ),
), ),
body: SingleChildScrollView( body: Column(
child: Column( crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 16, children: [
children: [ Expanded(
Padding( child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 12,
children: [ children: [
Text( Padding(
'نوع پروانه کسب', padding: const EdgeInsets.symmetric(
textAlign: TextAlign.center, horizontal: 20,
style: AppFonts.yekan12.copyWith( vertical: 10,
color: AppColor.blueNormal, ),
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) { if (data == 0) {
return NewCupertinoSegmentedControl<int>( selected.resetWith(0);
padding: EdgeInsets.zero, controller.routes.remove(route);
children: controller.segments, return;
groupValue: data.value, }
selectedColor: AppColor.blueNormal,
unselectedColor: Colors.white,
borderColor: Colors.grey.shade300,
onValueChanged: (int value) {
data.value = value;
},
);
}, controller.selectedSegment),
RTextField(label: 'صادر کننده پروانه'), controller.routes.ensureContainsAtStart(route);
RTextField(label: 'شماره مجوز'), selected.removeIfPresent(0);
RTextField(label: 'شماره ثبت'), selected.toggle(data);
RTextField(label: 'کد اقتصادی'), },
),
], ],
), ),
), ),
optionWidget(controller.selectedTypeOfOwnership), ),
optionWidget(controller.selectedAccompanyingInspectors),
optionWidget(controller.selectedUnitType),
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 20), padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
child: RElevated( child: RElevated(
text: 'مرحله بعد', text: 'مرحله بعد',
onPressed: () { onPressed: () {
Get.toNamed(InspectionRoutes.inspectionAddMobileInspector); Get.toNamed(controller.routes.first);
},
height: 40, },
isFullWidth: true, height: 50,
backgroundColor: AppColor.greenNormal, isFullWidth: true,
textStyle: AppFonts.yekan16.copyWith(color: Colors.white), 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( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 20), padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text( child: Text(
'نوع پروانه کسب', options.key,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: AppFonts.yekan12.copyWith(color: AppColor.blueNormal), style: AppFonts.yekan12.copyWith(color: AppColor.blueNormal),
), ),
), ),
SizedBox( SizedBox(
height: 75, height: 50,
child: ListView.separated( child: ListView.separated(
shrinkWrap: true, shrinkWrap: true,
padding: EdgeInsets.all(20), padding: EdgeInsets.symmetric(horizontal: 20),
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
itemBuilder: itemBuilder:
(context, index) => ObxValue((data) { (context, index) =>
return ChoiceChip( selected != null
onSelected: (value) { ? ObxValue((data) {
selected.value = index; return ChoiceChip(
}, onSelected: (_) => onSelected(index),
selectedColor: AppColor.blueNormal, color: WidgetStateProperty.resolveWith<Color?>((data,) {
labelStyle: if (selected.value == index) {
data.value == index return AppColor.blueNormal;
? AppFonts.yekan13.copyWith( } else {
color: AppColor.whiteLight, return Colors.white;
) }
: AppFonts.yekan12.copyWith( }),
color: AppColor.darkGreyNormalActive, labelStyle:
), data.value == index
checkmarkColor: Colors.white, ? AppFonts.yekan13.copyWith(
label: Text(controller.tmpLs[index]), color: AppColor.whiteLight,
selected: index == data.value, )
); : AppFonts.yekan12.copyWith(
}, selected), 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), 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( Expanded(
child: ROutlinedElevatedIcon( child: ROutlinedElevatedIcon(
icon: FaIcon(FontAwesomeIcons.calendar), 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: 'تا تاریخ', text: 'تا تاریخ',
textStyle: AppFonts.yekan16.copyWith( textStyle: AppFonts.yekan16.copyWith(
color: AppColor.blueNormal, color: AppColor.blueNormal,
@@ -140,7 +151,7 @@ class LocationDetailsPage extends GetView<LocationDetailsLogic> {
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 22, horizontal: 22,
vertical: 25, vertical: 21,
), ),
child: Column( child: Column(
spacing: 6, spacing: 6,
@@ -154,7 +165,7 @@ class LocationDetailsPage extends GetView<LocationDetailsLogic> {
), ),
SizedBox(height: 2), SizedBox(height: 2),
Text( Text(
'1043/12/12', '1403/12/12',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: AppFonts.yekan12, style: AppFonts.yekan12,
), ),

View File

@@ -1,10 +1,8 @@
import 'package:flutter/material.dart'; 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/registration_of_violation/logic.dart';
import 'package:inspection/presentation/routes/app_routes.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 class RegistrationOfViolationPage
extends GetView<RegistrationOfViolationLogic> { extends GetView<RegistrationOfViolationLogic> {
@@ -13,7 +11,7 @@ class RegistrationOfViolationPage
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor:AppColor.bgLight, backgroundColor: AppColor.bgLight,
appBar: RAppBar( appBar: RAppBar(
title: 'ثبت تخلف', title: 'ثبت تخلف',
leading: vecWidget( leading: vecWidget(
@@ -27,77 +25,83 @@ backgroundColor:AppColor.bgLight,
], ],
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20,vertical: 10), padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
child: Column( child: Column(
children: [ children: [
Expanded( Expanded(
child: ObxValue((data) { child: ObxValue((data) {
return ListView.separated( return ListView.separated(
itemBuilder: (context, index) =>Container( itemBuilder:
padding:EdgeInsets.symmetric(horizontal: 8,vertical: 12), (context, index) => Container(
decoration: BoxDecoration( padding: EdgeInsets.symmetric(
borderRadius: BorderRadius.circular(8), horizontal: 8,
border: Border.all(width: 1,color: AppColor.bgDark), vertical: 12,
),
child: Column(
spacing:16 ,
children: [
RTextField(
label: 'عنوان تخلف',
filled: true,
filledColor: AppColor.whiteLight,
), ),
RTextField( decoration: BoxDecoration(
label: 'توضیحات تخلف', borderRadius: BorderRadius.circular(8),
filled: true, border: Border.all(width: 0.75, color: AppColor.bgDark),
filledColor: AppColor.whiteLight,
maxLines: 5,
minLines: 5,
), ),
RTextField( child: Column(
label: 'عنوان تخلف', spacing: 16,
filled: true, children: [
filledColor: AppColor.whiteLight, RTextField(
label: 'عنوان تخلف',
filled: true,
filledColor: AppColor.whiteLight,
),
RTextField(
label: 'توضیحات تخلف',
filled: true,
filledColor: AppColor.whiteLight,
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: 3,
minLines: 3,
),
SizedBox(
height: 40,
child: Row(
spacing: 16,
children: [
Expanded(
child: RElevated(
text: 'ثبت',
onPressed: () {},
),
),
Expanded(
child: ROutlinedElevated(
text: 'انصراف',
onPressed: () {},
),
),
],
),
),
],
), ),
RTextField( ),
label: 'عنوان تخلف', separatorBuilder: (context, index) => SizedBox(height: 15),
filled: true,
filledColor: AppColor.whiteLight,
),
RTextField(
label: 'توضیحات تخلف',
filled: true,
filledColor: AppColor.whiteLight,
maxLines: 5,
minLines: 5,
),
SizedBox(
height: 40,
child: Row(
spacing: 16,
children: [
Expanded(child: RElevated(text: 'ثبت', onPressed: (){})),
Expanded(child:ROutlinedElevated(text: 'انصراف',onPressed: (){},) ),
],
),
)
],
),
) ,
separatorBuilder: (context, index) => SizedBox(height: 15,),
itemCount: data.value, itemCount: data.value,
); );
},controller.countViolation), }, controller.countViolation),
), ),
RElevated( RElevated(
@@ -110,7 +114,7 @@ backgroundColor:AppColor.bgLight,
backgroundColor: AppColor.greenNormal, backgroundColor: AppColor.greenNormal,
textStyle: AppFonts.yekan16.copyWith(color: Colors.white), 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:flutter/material.dart';
import 'package:rasadyar_app/domain/service/user/user_service.dart'; import 'package:rasadyar_app/domain/service/user/user_service.dart';
import 'package:rasadyar_app/presentation/routes/app_pages.dart'; import 'package:rasadyar_app/presentation/routes/app_pages.dart';
@@ -12,11 +11,9 @@ void main() async {
await setupAllProvider(); await setupAllProvider();
runApp(MyApp()); runApp(MyApp());
// runApp(DevicePreview(builder: (context) => ForDevicePreview(),)); // runApp(DevicePreview(builder: (context) => ForDevicePreview(),));
} }
/*class ForDevicePreview extends StatelessWidget { /*class ForDevicePreview extends StatelessWidget {
const ForDevicePreview({super.key}); const ForDevicePreview({super.key});
@@ -51,6 +48,10 @@ class MyApp extends StatelessWidget {
initialBinding: BindingsBuilder.put(() => UserService()), initialBinding: BindingsBuilder.put(() => UserService()),
getPages: AppPages.pages, getPages: AppPages.pages,
locale: Locale('fa'), 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:flutter_slidable/flutter_slidable.dart';
export 'package:font_awesome_flutter/font_awesome_flutter.dart'; export 'package:font_awesome_flutter/font_awesome_flutter.dart';
export 'package:flutter_rating_bar/flutter_rating_bar.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 'color_utils.dart';
export 'list_extensions.dart';

View File

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

View File

@@ -1,110 +1,115 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart'; import 'package:rasadyar_core/core.dart';
@immutable @immutable
class RTextField extends StatefulWidget { class RTextField extends StatefulWidget {
RTextField( RTextField({
{super.key, super.key,
this.maxLines, this.maxLines,
this.maxLength, this.maxLength,
this.hintText, this.hintText,
this.padding, this.padding,
this.onChanged, this.onChanged,
this.onSubmitted, this.onSubmitted,
this.keyboardType, this.keyboardType,
this.showCounter = false, this.showCounter = false,
this.isDense, this.isDense,
this.initText, this.initText,
this.isForNumber = false, this.isForNumber = false,
this.style, this.style,
this.hintStyle, this.hintStyle,
this.suffixIcon, this.suffixIcon,
this.prefixIcon, this.prefixIcon,
this.validator, this.validator,
this.readonly = false, this.readonly = false,
this.boxConstraints, this.boxConstraints,
this.minLines, this.minLines,
this.radius, this.radius,
this.filled, this.filled,
this.filledColor, this.filledColor,
this.enabled, this.enabled,
this.errorStyle, this.errorStyle,
this.labelStyle, this.labelStyle,
this.label}) { this.label,
}) {
filled = filled ?? false; filled = filled ?? false;
obscure = false; obscure = false;
_inputBorder = OutlineInputBorder( _inputBorder = OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade300), borderSide: BorderSide(color: Colors.grey.shade300),
borderRadius: BorderRadius.circular(radius ?? 16)); borderRadius: BorderRadius.circular(radius ?? 8),
);
} }
RTextField.noBorder( RTextField.noBorder({
{super.key, super.key,
this.maxLines, this.maxLines,
this.maxLength, this.maxLength,
this.hintText, this.hintText,
this.padding, this.padding,
this.onChanged, this.onChanged,
this.onSubmitted, this.onSubmitted,
this.keyboardType, this.keyboardType,
this.showCounter = false, this.showCounter = false,
this.isDense, this.isDense,
this.initText, this.initText,
this.style, this.style,
this.hintStyle, this.hintStyle,
this.suffixIcon, this.suffixIcon,
this.radius, this.radius,
this.validator, this.validator,
this.boxConstraints, this.boxConstraints,
this.minLines, this.minLines,
this.isForNumber = false, this.isForNumber = false,
this.readonly = false, this.readonly = false,
this.label, this.label,
this.filled, this.filled,
this.filledColor, this.filledColor,
this.errorStyle, this.errorStyle,
this.labelStyle, this.labelStyle,
this.enabled}) { this.enabled,
}) {
_inputBorder = OutlineInputBorder( _inputBorder = OutlineInputBorder(
borderSide: BorderSide.none, borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(radius ?? 16)); borderRadius: BorderRadius.circular(radius ?? 16),
);
obscure = false; obscure = false;
filled = filled ?? true; filled = filled ?? true;
} }
RTextField.password( RTextField.password({
{super.key, super.key,
this.maxLines = 1, this.maxLines = 1,
this.maxLength, this.maxLength,
this.hintText, this.hintText,
this.padding, this.padding,
this.onChanged, this.onChanged,
this.onSubmitted, this.onSubmitted,
this.keyboardType, this.keyboardType,
this.showCounter = false, this.showCounter = false,
this.isDense, this.isDense,
this.initText, this.initText,
this.style, this.style,
this.hintStyle, this.hintStyle,
this.suffixIcon, this.suffixIcon,
this.prefixIcon, this.prefixIcon,
this.radius, this.radius,
this.validator, this.validator,
this.boxConstraints, this.boxConstraints,
this.minLines, this.minLines,
this.isForNumber = false, this.isForNumber = false,
this.readonly = false, this.readonly = false,
this.label, this.label,
this.filled, this.filled,
this.filledColor, this.filledColor,
this.errorStyle, this.errorStyle,
this.labelStyle, this.labelStyle,
this.enabled}) { this.enabled,
}) {
_inputBorder = OutlineInputBorder( _inputBorder = OutlineInputBorder(
borderSide: BorderSide.none, borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(radius ?? 16)); borderRadius: BorderRadius.circular(radius ?? 16),
);
filled = filled ?? true; filled = filled ?? true;
obscure = true; obscure = true;
_isPassword = true; _isPassword = true;
@@ -170,53 +175,61 @@ class _RTextFieldState extends State<RTextField> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Padding(
padding: widget.padding ?? const EdgeInsets.symmetric(vertical: 6.0), padding: widget.padding ?? EdgeInsets.zero,
child: TextFormField( child: TextFormField(
controller: _controller, controller: _controller,
readOnly: widget.readonly, readOnly: widget.readonly,
minLines: widget.minLines, minLines: widget.minLines,
maxLines: widget.maxLines, maxLines: widget.maxLines,
onChanged: widget.onChanged, onChanged: widget.onChanged,
validator: widget.validator, validator: widget.validator,
enabled: widget.enabled, enabled: widget.enabled,
obscureText: obscure ?? false, obscureText: obscure ?? false,
onTapOutside: (event) { onTapOutside: (event) {
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
}, },
onFieldSubmitted: widget.onSubmitted, onFieldSubmitted: widget.onSubmitted,
maxLength: widget.maxLength, maxLength: widget.maxLength,
textDirection: TextDirection.rtl, textDirection: TextDirection.rtl,
style: widget.style , style: widget.style,
keyboardType: widget.keyboardType, keyboardType: widget.keyboardType,
decoration: InputDecoration( decoration: InputDecoration(
errorStyle: widget.errorStyle, contentPadding: EdgeInsets.symmetric(horizontal: 16),
errorMaxLines: 1, errorStyle: widget.errorStyle,
isDense: widget.isDense, errorMaxLines: 1,
suffixIcon: widget.suffixIcon ?? isDense: widget.isDense,
(widget._isPassword suffixIcon:
? IconButton( widget.suffixIcon ??
onPressed: () { (widget._isPassword
setState(() { ? IconButton(
obscure = !obscure!; onPressed: () {
}); setState(() {
}, obscure = !obscure!;
icon: Icon(!obscure! });
? CupertinoIcons.eye_slash },
: CupertinoIcons.eye)) icon: Icon(
: null), !obscure! ? CupertinoIcons.eye_slash : CupertinoIcons.eye,
suffixIconConstraints: widget.boxConstraints, ),
prefixIcon: widget.prefixIcon, )
prefixIconConstraints: widget.boxConstraints, : null),
hintText: widget.hintText, suffixIconConstraints: widget.boxConstraints,
labelText: widget.label, prefixIcon: widget.prefixIcon,
labelStyle: widget.labelStyle??AppFonts.yekan14.copyWith(color: AppColor.lightGreyDarkActive), prefixIconConstraints: widget.boxConstraints,
filled: widget.filled, hintText: widget.hintText,
fillColor: widget.filledColor, labelText: widget.label,
counter: widget.showCounter ? null : const SizedBox(), alignLabelWithHint: true,
hintStyle: widget.hintStyle, labelStyle: AppFonts.yekan14
enabledBorder: widget._inputBorder, .copyWith(color: AppColor.lightGreyDarkActive)
focusedBorder: widget._inputBorder, .merge(widget.labelStyle),
border: widget._inputBorder), filled: widget.filled,
)); fillColor: widget.filledColor,
counter: widget.showCounter ? null : const SizedBox(),
hintStyle: widget.hintStyle,
enabledBorder: widget._inputBorder,
focusedBorder: widget._inputBorder,
border: widget._inputBorder,
),
),
);
} }
} }