improvements

design_3.0_TM_Module_snagsFix
Sikander Saleem 8 months ago
parent eead9bed02
commit 0a38bdd9e1

@ -12,7 +12,7 @@ extension BuildContextExtension on BuildContext {
List<String> get getIssues => [translation.reason1, translation.reason2, translation.reason3, translation.reason4, translation.reason5]; List<String> get getIssues => [translation.reason1, translation.reason2, translation.reason3, translation.reason4, translation.reason5];
bool get isDark => Provider.of<SettingProvider>(this).theme == "dark"; bool get isDark => Provider.of<SettingProvider>(this, listen: false).theme == "dark";
bool get isAr => Provider.of<SettingProvider>(this).language == "ar"; bool get isAr => Provider.of<SettingProvider>(this).language == "ar";
@ -28,7 +28,7 @@ extension BuildContextExtension on BuildContext {
), ),
); );
void showBottomSheet(Widget childWidget, {bool? isDismissible, String? title}) => showModalBottomSheet( Future showBottomSheet(Widget childWidget, {bool? isDismissible, String? title}) => showModalBottomSheet(
context: this, context: this,
useSafeArea: true, useSafeArea: true,
isScrollControlled: true, isScrollControlled: true,

@ -175,7 +175,7 @@ class CreateServiceRequestPageState extends State<CreateServiceRequestPage> {
children: [ children: [
Text(context.translation.priority, style: Theme.of(context).textTheme.bodyLarge), Text(context.translation.priority, style: Theme.of(context).textTheme.bodyLarge),
Consumer<PriorityProvider>(builder: (cxt, snapshot, _) { Consumer<PriorityProvider>(builder: (cxt, snapshot, _) {
_serviceRequest.priority ??= snapshot.items.firstWhere((element) => element.value == 0, orElse: null); _serviceRequest.priority ??= snapshot.items.firstWhere((element) => element.value == 0, orElse: null);
return Transform.scale( return Transform.scale(
scale: 0.8, scale: 0.8,
@ -185,9 +185,9 @@ class CreateServiceRequestPageState extends State<CreateServiceRequestPage> {
value: _serviceRequest.priority?.value != 0, value: _serviceRequest.priority?.value != 0,
onChanged: (state) { onChanged: (state) {
if (state) { if (state) {
_serviceRequest.priority = snapshot.items.firstWhere((element) => element.value == 1, orElse: null); _serviceRequest.priority = snapshot.items.firstWhere((element) => element.value == 1, orElse: null);
} else { } else {
_serviceRequest.priority = snapshot.items.firstWhere((element) => element.value == 0, orElse: null); _serviceRequest.priority = snapshot.items.firstWhere((element) => element.value == 0, orElse: null);
} }
setState(() {}); setState(() {});
}).toShimmer(isShow: snapshot.loading), }).toShimmer(isShow: snapshot.loading),
@ -375,8 +375,8 @@ class CreateServiceRequestPageState extends State<CreateServiceRequestPage> {
} }
Future<void> _submit() async { Future<void> _submit() async {
_serviceRequest.requestedThrough = Provider.of<RequestedThroughProvider>(context, listen: false).items.firstWhere((element) => element.value == 3, orElse: null); _serviceRequest.requestedThrough = Provider.of<RequestedThroughProvider>(context, listen: false).items.firstWhere((element) => element.value == 3, orElse: null);
_serviceRequest.type = Provider.of<TypeOfRequestProvider>(context, listen: false).items.firstWhere((element) => element.value == 1, orElse: null); _serviceRequest.type = Provider.of<TypeOfRequestProvider>(context, listen: false).items.firstWhere((element) => element.value == 1, orElse: null);
// print("_serviceRequest?.requestedThrough:${_serviceRequest?.requestedThrough.toJson()}"); // print("_serviceRequest?.requestedThrough:${_serviceRequest?.requestedThrough.toJson()}");
// print("_serviceRequest?.type:${_serviceRequest?.type.toJson()}"); // print("_serviceRequest?.type:${_serviceRequest?.type.toJson()}");

@ -182,66 +182,110 @@ class _MultiFilesPickerState extends State<MultiFilesPicker> {
); );
} }
Widget gridItemNew(String icon, String label) {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: const Color(0xffF1F1F1), width: 1),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
icon.toSvgAsset(),
label.bodyText2(context).custom(color: AppColor.black20),
],
),
);
}
onFilePicker() async { onFilePicker() async {
if (widget.files.length >= 5) { if (widget.files.length >= 5) {
Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5); Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5);
return; return;
} }
ImageSource? source = await showModalBottomSheet<ImageSource>(
context: context,
builder: (BuildContext context) {
Widget listCard({required String icon, required String label, required VoidCallback onTap}) {
return GestureDetector(
onTap: onTap,
child: Container(
constraints: BoxConstraints(minWidth: 111.toScreenWidth, minHeight: 111.toScreenHeight),
padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth, vertical: 12.toScreenHeight),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), border: Border.all(width: 1, color: AppColor.white70)),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
icon.toSvgAsset(),
24.height,
label.bodyText2(context).custom(color: AppColor.black20),
],
),
),
);
}
return Container( ImageSource? source = await context.showBottomSheet(
padding: const EdgeInsets.all(16.0), GridView(
child: Row( padding: const EdgeInsets.all(0),
mainAxisAlignment: MainAxisAlignment.spaceBetween, shrinkWrap: true,
children: <Widget>[ physics: const NeverScrollableScrollPhysics(),
listCard( gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1, crossAxisSpacing: 12, mainAxisSpacing: 12),
icon: 'camera_icon', children: <Widget>[
label: '${context.translation.open}\n${context.translation.camera}', gridItemNew('camera_icon', context.translation.pickFromCamera).onPress(() => Navigator.of(context).pop(ImageSource.camera)),
onTap: () { gridItemNew('gallery_icon', context.translation.pickFromGallery).onPress(() => Navigator.of(context).pop(ImageSource.gallery)),
Navigator.of(context).pop(ImageSource.camera); gridItemNew('file_icon', context.translation.pickFromFiles).onPress(() async {
}, await fromFilePicker();
), Navigator.pop(context);
listCard( }),
icon: 'gallery_icon', ],
label: '${context.translation.open}\n${context.translation.gallery}', ),
onTap: () { title: "Attach File");
Navigator.of(context).pop(ImageSource.gallery); //
}, // showModalBottomSheet<ImageSource>(
), // context: context,
listCard( // builder: (BuildContext context) {
icon: 'file_icon', // return;
label: '${context.translation.open}\n${context.translation.files}', // },
onTap: () async { // );
await fromFilePicker();
Navigator.pop(context); // ImageSource? source = await showModalBottomSheet<ImageSource>(
}, // context: context,
), // builder: (BuildContext context) {
], // Widget listCard({required String icon, required String label, required VoidCallback onTap}) {
), // return GestureDetector(
); // onTap: onTap,
}, // child: Container(
); // constraints: BoxConstraints(minWidth: 111.toScreenWidth, minHeight: 111.toScreenHeight),
// padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth, vertical: 12.toScreenHeight),
// decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), border: Border.all(width: 1, color: AppColor.white70)),
// child: Column(
// mainAxisSize: MainAxisSize.min,
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// icon.toSvgAsset(),
// 24.height,
// label.bodyText2(context).custom(color: AppColor.black20),
// ],
// ),
// ),
// );
// }
//
// return Container(
// padding: const EdgeInsets.all(16.0),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: <Widget>[
// listCard(
// icon: 'camera_icon',
// label: '${context.translation.open}\n${context.translation.camera}',
// onTap: () {
// Navigator.of(context).pop(ImageSource.camera);
// },
// ),
// listCard(
// icon: 'gallery_icon',
// label: '${context.translation.open}\n${context.translation.gallery}',
// onTap: () {
// Navigator.of(context).pop(ImageSource.gallery);
// },
// ),
// listCard(
// icon: 'file_icon',
// label: '${context.translation.open}\n${context.translation.files}',
// onTap: () async {
// await fromFilePicker();
// Navigator.pop(context);
// },
// ),
// ],
// ),
// );
// },
// );
// ImageSource source = await showDialog( // ImageSource source = await showDialog(
// context: context, // context: context,
// builder: (dialogContext) => CupertinoAlertDialog( // builder: (dialogContext) => CupertinoAlertDialog(
@ -304,267 +348,267 @@ class AttachmentModel {
} }
} }
class AttachmentPicker extends StatefulWidget { // class AttachmentPicker extends StatefulWidget {
final String label; // final String label;
final bool error; // final bool error;
final List<AttachmentModel> attachment; // final List<AttachmentModel> attachment;
//
final bool enabled, onlyImages; // final bool enabled, onlyImages;
double? buttonHeight; // double? buttonHeight;
Widget? buttonIcon; // Widget? buttonIcon;
Color? buttonColor; // Color? buttonColor;
final Function(List<AttachmentModel>)? onChange; // final Function(List<AttachmentModel>)? onChange;
final bool showAsGrid; // final bool showAsGrid;
//
AttachmentPicker( // AttachmentPicker(
{Key? key, // {Key? key,
this.attachment = const <AttachmentModel>[], // this.attachment = const <AttachmentModel>[],
required this.label, // required this.label,
this.error = false, // this.error = false,
this.buttonHeight, // this.buttonHeight,
this.buttonIcon, // this.buttonIcon,
this.enabled = true, // this.enabled = true,
this.onlyImages = false, // this.onlyImages = false,
this.onChange, // this.onChange,
this.showAsGrid = false, // this.showAsGrid = false,
this.buttonColor}) // this.buttonColor})
: super(key: key); // : super(key: key);
//
@override // @override
State<AttachmentPicker> createState() => _AttachmentPickerState(); // State<AttachmentPicker> createState() => _AttachmentPickerState();
} // }
//
class _AttachmentPickerState extends State<AttachmentPicker> { // class _AttachmentPickerState extends State<AttachmentPicker> {
@override // @override
Widget build(BuildContext context) { // Widget build(BuildContext context) {
return Column( // return Column(
crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
children: [ // children: [
AppDashedButton( // AppDashedButton(
title: widget.label, // title: widget.label,
height: widget.buttonHeight, // height: widget.buttonHeight,
buttonColor: widget.buttonColor, // buttonColor: widget.buttonColor,
icon: widget.buttonIcon, // icon: widget.buttonIcon,
onPressed: (widget.enabled == false) // onPressed: (widget.enabled == false)
? () {} // ? () {}
: widget.showAsGrid // : widget.showAsGrid
? showFileSourceSheet // ? showFileSourceSheet
: onFilePicker), // : onFilePicker),
16.height, // 16.height,
if (widget.attachment.isNotEmpty) // if (widget.attachment.isNotEmpty)
Wrap( // Wrap(
spacing: 8.toScreenWidth, // spacing: 8.toScreenWidth,
children: List.generate( // children: List.generate(
widget.attachment.length, // widget.attachment.length,
(index) { // (index) {
File image = widget.attachment[index].file!; // File image = widget.attachment[index].file!;
return MultiFilesPickerItem( // return MultiFilesPickerItem(
file: image, // file: image,
enabled: widget.enabled, // enabled: widget.enabled,
onRemoveTap: (image) { // onRemoveTap: (image) {
if (!widget.enabled) { // if (!widget.enabled) {
return; // return;
} // }
widget.attachment.remove(image); // widget.attachment.remove(image);
if (widget.onChange != null) { // if (widget.onChange != null) {
widget.onChange!(widget.attachment); // widget.onChange!(widget.attachment);
} // }
setState(() {}); // setState(() {});
}, // },
); // );
}, // },
), // ),
), // ),
], // ],
); // );
} // }
//
fromFilePicker() async { // fromFilePicker() async {
FilePickerResult? result = await FilePicker.platform.pickFiles( // FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.custom, // type: FileType.custom,
allowMultiple: true, // allowMultiple: true,
allowedExtensions: widget.onlyImages ? ['jpg', 'jpeg', 'png'] : ['jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'xlsx', 'pptx'], // allowedExtensions: widget.onlyImages ? ['jpg', 'jpeg', 'png'] : ['jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'xlsx', 'pptx'],
); // );
if (result != null) { // if (result != null) {
for (var path in result.paths) { // for (var path in result.paths) {
widget.attachment.add(AttachmentModel(0, File(path!))); // widget.attachment.add(AttachmentModel(0, File(path!)));
} // }
setState(() {}); // setState(() {});
} // }
} // }
//
void showFileSourceSheet() async { // void showFileSourceSheet() async {
if (widget.attachment.length >= 5) { // if (widget.attachment.length >= 5) {
Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5); // Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5);
return; // return;
} // }
//
ImageSource source = (await showModalBottomSheet( // ImageSource source = (await showModalBottomSheet(
context: context, // context: context,
shape: const RoundedRectangleBorder( // shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical( // borderRadius: BorderRadius.vertical(
top: Radius.circular(20), // top: Radius.circular(20),
), // ),
), // ),
clipBehavior: Clip.antiAliasWithSaveLayer, // clipBehavior: Clip.antiAliasWithSaveLayer,
builder: (BuildContext context) => Column( // builder: (BuildContext context) => Column(
mainAxisSize: MainAxisSize.min, // mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
children: [ // children: [
"Attach File".heading4(context), // "Attach File".heading4(context),
12.height, // 12.height,
GridView( // GridView(
padding: const EdgeInsets.all(0), // padding: const EdgeInsets.all(0),
shrinkWrap: true, // shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), // physics: const NeverScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1, crossAxisSpacing: 12, mainAxisSpacing: 12), // gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1, crossAxisSpacing: 12, mainAxisSpacing: 12),
children: <Widget>[ // children: <Widget>[
gridItem(Icons.camera_enhance_rounded, context.translation.pickFromCamera).onPress(() => Navigator.of(context).pop(ImageSource.camera)), // gridItem(Icons.camera_enhance_rounded, context.translation.pickFromCamera).onPress(() => Navigator.of(context).pop(ImageSource.camera)),
gridItem(Icons.image_rounded, context.translation.pickFromGallery).onPress(() => Navigator.of(context).pop(ImageSource.gallery)), // gridItem(Icons.image_rounded, context.translation.pickFromGallery).onPress(() => Navigator.of(context).pop(ImageSource.gallery)),
gridItem(Icons.file_present_rounded, context.translation.pickFromFiles).onPress(() async { // gridItem(Icons.file_present_rounded, context.translation.pickFromFiles).onPress(() async {
await fromFilePicker(); // await fromFilePicker();
Navigator.pop(context); // Navigator.pop(context);
}), // }),
], // ],
), // ),
12.height, // 12.height,
], // ],
).paddingAll(21), // ).paddingAll(21),
)) as ImageSource; // )) as ImageSource;
//
final pickedFile = await ImagePicker().pickImage(source: source, imageQuality: 70, maxWidth: 800, maxHeight: 800); // final pickedFile = await ImagePicker().pickImage(source: source, imageQuality: 70, maxWidth: 800, maxHeight: 800);
//
if (pickedFile != null) { // if (pickedFile != null) {
File fileImage = File(pickedFile.path); // File fileImage = File(pickedFile.path);
widget.attachment.add(AttachmentModel(0, fileImage)); // widget.attachment.add(AttachmentModel(0, fileImage));
if (widget.onChange != null) { // if (widget.onChange != null) {
widget.onChange!(widget.attachment); // widget.onChange!(widget.attachment);
} // }
setState(() {}); // setState(() {});
} // }
} // }
//
Widget gridItem(IconData iconData, String title) { // Widget gridItem(IconData iconData, String title) {
return Container( // return Container(
padding: const EdgeInsets.all(12), // padding: const EdgeInsets.all(12),
decoration: BoxDecoration( // decoration: BoxDecoration(
color: Colors.white, // color: Colors.white,
borderRadius: BorderRadius.circular(12), // borderRadius: BorderRadius.circular(12),
border: Border.all(color: const Color(0xffF1F1F1), width: 1), // border: Border.all(color: const Color(0xffF1F1F1), width: 1),
), // ),
child: Column( // child: Column(
crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween, // mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ // children: [
Icon(iconData, color: const Color(0xff7D859A), size: 36), // Icon(iconData, color: const Color(0xff7D859A), size: 36),
Text( // Text(
title, // title,
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w500), // style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
), // ),
], // ],
), // ),
); // );
} // }
//
onFilePicker() async { // onFilePicker() async {
if (widget.attachment.length >= 5) { // if (widget.attachment.length >= 5) {
Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5); // Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5);
return; // return;
} // }
ImageSource? source = await showModalBottomSheet<ImageSource>( // ImageSource? source = await showModalBottomSheet<ImageSource>(
context: context, // context: context,
builder: (BuildContext context) { // builder: (BuildContext context) {
Widget listCard({required String icon, required String label, required VoidCallback onTap}) { // Widget listCard({required String icon, required String label, required VoidCallback onTap}) {
return GestureDetector( // return GestureDetector(
onTap: onTap, // onTap: onTap,
child: Container( // child: Container(
constraints: BoxConstraints(minWidth: 111.toScreenWidth, minHeight: 111.toScreenHeight), // constraints: BoxConstraints(minWidth: 111.toScreenWidth, minHeight: 111.toScreenHeight),
padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth, vertical: 12.toScreenHeight), // padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth, vertical: 12.toScreenHeight),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), border: Border.all(width: 1, color: AppColor.white70)), // decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), border: Border.all(width: 1, color: AppColor.white70)),
child: Column( // child: Column(
mainAxisSize: MainAxisSize.min, // mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
children: [ // children: [
icon.toSvgAsset(), // icon.toSvgAsset(),
24.height, // 24.height,
label.bodyText2(context).custom(color: AppColor.black20), // label.bodyText2(context).custom(color: AppColor.black20),
], // ],
), // ),
), // ),
); // );
} // }
//
return Container( // return Container(
padding: const EdgeInsets.all(16.0), // padding: const EdgeInsets.all(16.0),
child: Row( // child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, // mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[ // children: <Widget>[
listCard( // listCard(
icon: 'camera_icon', // icon: 'camera_icon',
label: '${context.translation.open}\n${context.translation.camera}', // label: '${context.translation.open}\n${context.translation.camera}',
onTap: () { // onTap: () {
Navigator.of(context).pop(ImageSource.camera); // Navigator.of(context).pop(ImageSource.camera);
}, // },
), // ),
listCard( // listCard(
icon: 'gallery_icon', // icon: 'gallery_icon',
label: '${context.translation.open}\n${context.translation.gallery}', // label: '${context.translation.open}\n${context.translation.gallery}',
onTap: () { // onTap: () {
Navigator.of(context).pop(ImageSource.gallery); // Navigator.of(context).pop(ImageSource.gallery);
}, // },
), // ),
listCard( // listCard(
icon: 'file_icon', // icon: 'file_icon',
label: '${context.translation.open}\n${context.translation.files}', // label: '${context.translation.open}\n${context.translation.files}',
onTap: () async { // onTap: () async {
await fromFilePicker(); // await fromFilePicker();
Navigator.pop(context); // Navigator.pop(context);
}, // },
), // ),
], // ],
), // ),
); // );
}, // },
); // );
// ImageSource source = await showDialog( // // ImageSource source = await showDialog(
// context: context, // // context: context,
// builder: (dialogContext) => CupertinoAlertDialog( // // builder: (dialogContext) => CupertinoAlertDialog(
// actions: <Widget>[ // // actions: <Widget>[
// TextButton( // // TextButton(
// child: Text(context.translation.pickFromCamera), // // child: Text(context.translation.pickFromCamera),
// onPressed: () { // // onPressed: () {
// Navigator.of(dialogContext).pop(ImageSource.camera); // // Navigator.of(dialogContext).pop(ImageSource.camera);
// }, // // },
// ), // // ),
// TextButton( // // TextButton(
// child: Text(context.translation.pickFromGallery), // // child: Text(context.translation.pickFromGallery),
// onPressed: () { // // onPressed: () {
// Navigator.of(dialogContext).pop(ImageSource.gallery); // // Navigator.of(dialogContext).pop(ImageSource.gallery);
// }, // // },
// ), // // ),
// TextButton( // // TextButton(
// child: Text(context.translation.pickFromFiles), // // child: Text(context.translation.pickFromFiles),
// onPressed: () async { // // onPressed: () async {
// await fromFilePicker(); // // await fromFilePicker();
// Navigator.pop(context); // // Navigator.pop(context);
// }, // // },
// ), // // ),
// ], // // ],
// ), // // ),
// ); // // );
if (source == null) return; // if (source == null) return;
//
final pickedFile = await ImagePicker().pickImage(source: source, imageQuality: 70, maxWidth: 800, maxHeight: 800); // final pickedFile = await ImagePicker().pickImage(source: source, imageQuality: 70, maxWidth: 800, maxHeight: 800);
//
if (pickedFile != null) { // if (pickedFile != null) {
File fileImage = File(pickedFile.path); // File fileImage = File(pickedFile.path);
widget.attachment.add(AttachmentModel(0, fileImage)); // widget.attachment.add(AttachmentModel(0, fileImage));
if (widget.onChange != null) { // if (widget.onChange != null) {
widget.onChange!(widget.attachment); // widget.onChange!(widget.attachment);
} // }
setState(() {}); // setState(() {});
} // }
//
setState(() {}); // setState(() {});
} // }
} // }

Loading…
Cancel
Save