diff --git a/lib/extensions/context_extension.dart b/lib/extensions/context_extension.dart index 655a67d4..70c934b9 100644 --- a/lib/extensions/context_extension.dart +++ b/lib/extensions/context_extension.dart @@ -12,7 +12,7 @@ extension BuildContextExtension on BuildContext { List get getIssues => [translation.reason1, translation.reason2, translation.reason3, translation.reason4, translation.reason5]; - bool get isDark => Provider.of(this).theme == "dark"; + bool get isDark => Provider.of(this, listen: false).theme == "dark"; bool get isAr => Provider.of(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, useSafeArea: true, isScrollControlled: true, diff --git a/lib/views/pages/user/requests/create_service_request_page.dart b/lib/views/pages/user/requests/create_service_request_page.dart index f07a197f..4b770357 100644 --- a/lib/views/pages/user/requests/create_service_request_page.dart +++ b/lib/views/pages/user/requests/create_service_request_page.dart @@ -175,7 +175,7 @@ class CreateServiceRequestPageState extends State { children: [ Text(context.translation.priority, style: Theme.of(context).textTheme.bodyLarge), Consumer(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( scale: 0.8, @@ -185,9 +185,9 @@ class CreateServiceRequestPageState extends State { value: _serviceRequest.priority?.value != 0, onChanged: (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 { - _serviceRequest.priority = snapshot.items.firstWhere((element) => element.value == 0, orElse: null); + _serviceRequest.priority = snapshot.items.firstWhere((element) => element.value == 0, orElse: null); } setState(() {}); }).toShimmer(isShow: snapshot.loading), @@ -375,8 +375,8 @@ class CreateServiceRequestPageState extends State { } Future _submit() async { - _serviceRequest.requestedThrough = Provider.of(context, listen: false).items.firstWhere((element) => element.value == 3, orElse: null); - _serviceRequest.type = Provider.of(context, listen: false).items.firstWhere((element) => element.value == 1, orElse: null); + _serviceRequest.requestedThrough = Provider.of(context, listen: false).items.firstWhere((element) => element.value == 3, orElse: null); + _serviceRequest.type = Provider.of(context, listen: false).items.firstWhere((element) => element.value == 1, orElse: null); // print("_serviceRequest?.requestedThrough:${_serviceRequest?.requestedThrough.toJson()}"); // print("_serviceRequest?.type:${_serviceRequest?.type.toJson()}"); diff --git a/lib/views/widgets/images/multi_image_picker.dart b/lib/views/widgets/images/multi_image_picker.dart index 3f2282fa..40955bcf 100644 --- a/lib/views/widgets/images/multi_image_picker.dart +++ b/lib/views/widgets/images/multi_image_picker.dart @@ -182,66 +182,110 @@ class _MultiFilesPickerState extends State { ); } + 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 { if (widget.files.length >= 5) { Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5); return; } - ImageSource? source = await showModalBottomSheet( - 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: [ - 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 context.showBottomSheet( + GridView( + padding: const EdgeInsets.all(0), + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1, crossAxisSpacing: 12, mainAxisSpacing: 12), + children: [ + gridItemNew('camera_icon', context.translation.pickFromCamera).onPress(() => Navigator.of(context).pop(ImageSource.camera)), + gridItemNew('gallery_icon', context.translation.pickFromGallery).onPress(() => Navigator.of(context).pop(ImageSource.gallery)), + gridItemNew('file_icon', context.translation.pickFromFiles).onPress(() async { + await fromFilePicker(); + Navigator.pop(context); + }), + ], + ), + title: "Attach File"); + // + // showModalBottomSheet( + // context: context, + // builder: (BuildContext context) { + // return; + // }, + // ); + + // ImageSource? source = await showModalBottomSheet( + // 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: [ + // 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( // context: context, // builder: (dialogContext) => CupertinoAlertDialog( @@ -304,267 +348,267 @@ class AttachmentModel { } } -class AttachmentPicker extends StatefulWidget { - final String label; - final bool error; - final List attachment; - - final bool enabled, onlyImages; - double? buttonHeight; - Widget? buttonIcon; - Color? buttonColor; - final Function(List)? onChange; - final bool showAsGrid; - - AttachmentPicker( - {Key? key, - this.attachment = const [], - required this.label, - this.error = false, - this.buttonHeight, - this.buttonIcon, - this.enabled = true, - this.onlyImages = false, - this.onChange, - this.showAsGrid = false, - this.buttonColor}) - : super(key: key); - - @override - State createState() => _AttachmentPickerState(); -} - -class _AttachmentPickerState extends State { - @override - Widget build(BuildContext context) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - AppDashedButton( - title: widget.label, - height: widget.buttonHeight, - buttonColor: widget.buttonColor, - icon: widget.buttonIcon, - onPressed: (widget.enabled == false) - ? () {} - : widget.showAsGrid - ? showFileSourceSheet - : onFilePicker), - 16.height, - if (widget.attachment.isNotEmpty) - Wrap( - spacing: 8.toScreenWidth, - children: List.generate( - widget.attachment.length, - (index) { - File image = widget.attachment[index].file!; - return MultiFilesPickerItem( - file: image, - enabled: widget.enabled, - onRemoveTap: (image) { - if (!widget.enabled) { - return; - } - widget.attachment.remove(image); - if (widget.onChange != null) { - widget.onChange!(widget.attachment); - } - setState(() {}); - }, - ); - }, - ), - ), - ], - ); - } - - fromFilePicker() async { - FilePickerResult? result = await FilePicker.platform.pickFiles( - type: FileType.custom, - allowMultiple: true, - allowedExtensions: widget.onlyImages ? ['jpg', 'jpeg', 'png'] : ['jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'xlsx', 'pptx'], - ); - if (result != null) { - for (var path in result.paths) { - widget.attachment.add(AttachmentModel(0, File(path!))); - } - setState(() {}); - } - } - - void showFileSourceSheet() async { - if (widget.attachment.length >= 5) { - Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5); - return; - } - - ImageSource source = (await showModalBottomSheet( - context: context, - shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.vertical( - top: Radius.circular(20), - ), - ), - clipBehavior: Clip.antiAliasWithSaveLayer, - builder: (BuildContext context) => Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - "Attach File".heading4(context), - 12.height, - GridView( - padding: const EdgeInsets.all(0), - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1, crossAxisSpacing: 12, mainAxisSpacing: 12), - children: [ - 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.file_present_rounded, context.translation.pickFromFiles).onPress(() async { - await fromFilePicker(); - Navigator.pop(context); - }), - ], - ), - 12.height, - ], - ).paddingAll(21), - )) as ImageSource; - - final pickedFile = await ImagePicker().pickImage(source: source, imageQuality: 70, maxWidth: 800, maxHeight: 800); - - if (pickedFile != null) { - File fileImage = File(pickedFile.path); - widget.attachment.add(AttachmentModel(0, fileImage)); - if (widget.onChange != null) { - widget.onChange!(widget.attachment); - } - setState(() {}); - } - } - - Widget gridItem(IconData iconData, String title) { - 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(iconData, color: const Color(0xff7D859A), size: 36), - Text( - title, - style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w500), - ), - ], - ), - ); - } - - onFilePicker() async { - if (widget.attachment.length >= 5) { - Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5); - return; - } - ImageSource? source = await showModalBottomSheet( - 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: [ - 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( - // context: context, - // builder: (dialogContext) => CupertinoAlertDialog( - // actions: [ - // TextButton( - // child: Text(context.translation.pickFromCamera), - // onPressed: () { - // Navigator.of(dialogContext).pop(ImageSource.camera); - // }, - // ), - // TextButton( - // child: Text(context.translation.pickFromGallery), - // onPressed: () { - // Navigator.of(dialogContext).pop(ImageSource.gallery); - // }, - // ), - // TextButton( - // child: Text(context.translation.pickFromFiles), - // onPressed: () async { - // await fromFilePicker(); - // Navigator.pop(context); - // }, - // ), - // ], - // ), - // ); - if (source == null) return; - - final pickedFile = await ImagePicker().pickImage(source: source, imageQuality: 70, maxWidth: 800, maxHeight: 800); - - if (pickedFile != null) { - File fileImage = File(pickedFile.path); - widget.attachment.add(AttachmentModel(0, fileImage)); - if (widget.onChange != null) { - widget.onChange!(widget.attachment); - } - setState(() {}); - } - - setState(() {}); - } -} +// class AttachmentPicker extends StatefulWidget { +// final String label; +// final bool error; +// final List attachment; +// +// final bool enabled, onlyImages; +// double? buttonHeight; +// Widget? buttonIcon; +// Color? buttonColor; +// final Function(List)? onChange; +// final bool showAsGrid; +// +// AttachmentPicker( +// {Key? key, +// this.attachment = const [], +// required this.label, +// this.error = false, +// this.buttonHeight, +// this.buttonIcon, +// this.enabled = true, +// this.onlyImages = false, +// this.onChange, +// this.showAsGrid = false, +// this.buttonColor}) +// : super(key: key); +// +// @override +// State createState() => _AttachmentPickerState(); +// } +// +// class _AttachmentPickerState extends State { +// @override +// Widget build(BuildContext context) { +// return Column( +// crossAxisAlignment: CrossAxisAlignment.start, +// children: [ +// AppDashedButton( +// title: widget.label, +// height: widget.buttonHeight, +// buttonColor: widget.buttonColor, +// icon: widget.buttonIcon, +// onPressed: (widget.enabled == false) +// ? () {} +// : widget.showAsGrid +// ? showFileSourceSheet +// : onFilePicker), +// 16.height, +// if (widget.attachment.isNotEmpty) +// Wrap( +// spacing: 8.toScreenWidth, +// children: List.generate( +// widget.attachment.length, +// (index) { +// File image = widget.attachment[index].file!; +// return MultiFilesPickerItem( +// file: image, +// enabled: widget.enabled, +// onRemoveTap: (image) { +// if (!widget.enabled) { +// return; +// } +// widget.attachment.remove(image); +// if (widget.onChange != null) { +// widget.onChange!(widget.attachment); +// } +// setState(() {}); +// }, +// ); +// }, +// ), +// ), +// ], +// ); +// } +// +// fromFilePicker() async { +// FilePickerResult? result = await FilePicker.platform.pickFiles( +// type: FileType.custom, +// allowMultiple: true, +// allowedExtensions: widget.onlyImages ? ['jpg', 'jpeg', 'png'] : ['jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'xlsx', 'pptx'], +// ); +// if (result != null) { +// for (var path in result.paths) { +// widget.attachment.add(AttachmentModel(0, File(path!))); +// } +// setState(() {}); +// } +// } +// +// void showFileSourceSheet() async { +// if (widget.attachment.length >= 5) { +// Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5); +// return; +// } +// +// ImageSource source = (await showModalBottomSheet( +// context: context, +// shape: const RoundedRectangleBorder( +// borderRadius: BorderRadius.vertical( +// top: Radius.circular(20), +// ), +// ), +// clipBehavior: Clip.antiAliasWithSaveLayer, +// builder: (BuildContext context) => Column( +// mainAxisSize: MainAxisSize.min, +// crossAxisAlignment: CrossAxisAlignment.start, +// children: [ +// "Attach File".heading4(context), +// 12.height, +// GridView( +// padding: const EdgeInsets.all(0), +// shrinkWrap: true, +// physics: const NeverScrollableScrollPhysics(), +// gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1, crossAxisSpacing: 12, mainAxisSpacing: 12), +// children: [ +// 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.file_present_rounded, context.translation.pickFromFiles).onPress(() async { +// await fromFilePicker(); +// Navigator.pop(context); +// }), +// ], +// ), +// 12.height, +// ], +// ).paddingAll(21), +// )) as ImageSource; +// +// final pickedFile = await ImagePicker().pickImage(source: source, imageQuality: 70, maxWidth: 800, maxHeight: 800); +// +// if (pickedFile != null) { +// File fileImage = File(pickedFile.path); +// widget.attachment.add(AttachmentModel(0, fileImage)); +// if (widget.onChange != null) { +// widget.onChange!(widget.attachment); +// } +// setState(() {}); +// } +// } +// +// Widget gridItem(IconData iconData, String title) { +// 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(iconData, color: const Color(0xff7D859A), size: 36), +// Text( +// title, +// style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w500), +// ), +// ], +// ), +// ); +// } +// +// onFilePicker() async { +// if (widget.attachment.length >= 5) { +// Fluttertoast.showToast(msg: context.translation.maxImagesNumberIs5); +// return; +// } +// ImageSource? source = await showModalBottomSheet( +// 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: [ +// 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( +// // context: context, +// // builder: (dialogContext) => CupertinoAlertDialog( +// // actions: [ +// // TextButton( +// // child: Text(context.translation.pickFromCamera), +// // onPressed: () { +// // Navigator.of(dialogContext).pop(ImageSource.camera); +// // }, +// // ), +// // TextButton( +// // child: Text(context.translation.pickFromGallery), +// // onPressed: () { +// // Navigator.of(dialogContext).pop(ImageSource.gallery); +// // }, +// // ), +// // TextButton( +// // child: Text(context.translation.pickFromFiles), +// // onPressed: () async { +// // await fromFilePicker(); +// // Navigator.pop(context); +// // }, +// // ), +// // ], +// // ), +// // ); +// if (source == null) return; +// +// final pickedFile = await ImagePicker().pickImage(source: source, imageQuality: 70, maxWidth: 800, maxHeight: 800); +// +// if (pickedFile != null) { +// File fileImage = File(pickedFile.path); +// widget.attachment.add(AttachmentModel(0, fileImage)); +// if (widget.onChange != null) { +// widget.onChange!(widget.attachment); +// } +// setState(() {}); +// } +// +// setState(() {}); +// } +// }