Untitled
unknown
dart
3 years ago
31 kB
6
Indexable
import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_absolute_path/flutter_absolute_path.dart'; import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; import 'package:image_cropper/image_cropper.dart'; import 'package:mobile/app/Dto/add_supplier_dto.dart'; import 'package:mobile/app/Dto/upload_supplier_document_dto.dart'; import 'package:mobile/app/global_widgets/circular_block_button_widget.dart'; import 'package:mobile/app/global_widgets/text_field_widget.dart'; import 'package:mobile/app/models/new/myfatoorah_bank.dart'; import 'package:mobile/app/modules/auth/controllers/auth_controller.dart'; import 'package:mobile/app/modules/auth/controllers/payment_info_controller.dart'; import 'package:mobile/app/providers/api_provider.dart'; import 'package:mobile/app/routes/app_pages.dart'; import 'package:mobile/common/ui.dart'; import 'package:file_picker/file_picker.dart'; import 'package:multi_image_picker2/multi_image_picker2.dart'; // import 'package:filesystem_picker/filesystem_picker.dart'; class PaymentInfoAdd extends GetView<PaymentInfoController> { var controller = Get.put(PaymentInfoController()); GetStorage box = GetStorage(); final GlobalKey<FormState> _loginForm = new GlobalKey<FormState>(); final AuthController authController = Get.find(); @override Widget build(BuildContext context) { return Obx( () => Scaffold( backgroundColor: Ui.parseColor('#F5F5F5'), extendBodyBehindAppBar: false, body: SafeArea( child: ListView( primary: true, children: [ Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( 'Payment Details'.tr, style: Get.theme.textTheme.headline2 .copyWith(fontWeight: FontWeight.bold), ), ], ).paddingSymmetric(horizontal: 16, vertical: 40), Form( key: _loginForm, autovalidateMode: AutovalidateMode.onUserInteraction, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.all( Radius.circular(15), ), color: Get.theme.primaryColor, boxShadow: [ BoxShadow( color: Get.theme.focusColor.withOpacity(0.2), blurRadius: 10, offset: Offset(0, 5)), ], ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Visibility( visible: controller.supplierCode != null || controller.errorSupplierFileUploadReg.value == true, child: Container( margin: EdgeInsets.all(15.0), child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ Icon( Icons.warning_amber_rounded, color: Colors.red, ), SizedBox( width: 10.0, ), Expanded( child: Text( "Please complete bank infromation details".tr, style: Get.textTheme.headline4 .copyWith(fontWeight: FontWeight.bold), ), ), ], ), ), ), Visibility( visible: controller.supplierCode == null, child: Column( children: [ Text( 'Bank Details'.tr, // textAlign: TextAlign.left, style: Get.textTheme.headline4 .copyWith(fontWeight: FontWeight.bold), ).paddingOnly(top: 20, left: 20, right: 20), SizedBox(height: 15), Text( 'Bank Name'.tr, // textAlign: TextAlign.left, style: Get.textTheme.bodyText2 .copyWith(fontWeight: FontWeight.bold), ).paddingOnly(top: 10, left: 50, right: 50), DropdownButton<String>( // itemHeight: 100, isExpanded: true, isDense: false, items: controller.myFatoorahBanks .map((MyFatoorahBank value) { return DropdownMenuItem<String>( value: value.Value.toString(), child: Text( value.Text, maxLines: 3, style: Get.textTheme.bodyText2, overflow: TextOverflow.visible, ), onTap: () { controller.bankNameFromList.value = value.Text.substring( (value.Text.indexOf('-') + 1) ?? 0); }, ); }).toList(), onChanged: (val) { controller.bankID = int.parse(val); }, hint: new Text( controller.bankNameFromList.value == '' ? 'Select Bank'.tr : controller.bankNameFromList.value, maxLines: 3, overflow: TextOverflow.visible, style: Get.theme.textTheme.bodyText1, ), ).paddingOnly(top: 10, left: 50, right: 50), TextFieldWidget( labelText: 'Account Number'.tr, hintText: "Please Enter Account Number".tr, iconData: Icons.pin, isFirst: true, isLast: false, controller: controller.accountNumber, validator: (value) => controller.validateEmpty( value, controller.accountNumber, 8), keyboardType: TextInputType.text, ), TextFieldWidget( labelText: 'IBAN Number'.tr, hintText: "Please Enter IBAN Number".tr, iconData: Icons.money, isFirst: true, isLast: false, controller: controller.iBANNumber, validator: (value) => controller.validateEmpty( value, controller.iBANNumber, 24), keyboardType: TextInputType.text, ), ], ), ).paddingOnly(top: 10, left: 10, right: 10), Text( 'National ID'.tr, // textAlign: TextAlign.left, style: Get.textTheme.headline4 .copyWith(fontWeight: FontWeight.bold), ).paddingOnly(top: 10, left: 20, right: 20, bottom: 10), Obx(() => controller.nationalIDFile.value.path.trim() != '' ? Card( elevation: 2, child: ListTile( title: Text( controller.nationalIDFile.value.path .substring(controller .nationalIDFile.value.path .lastIndexOf('/') + 1), style: TextStyle(color: Get.theme.focusColor), ), trailing: IconButton( onPressed: () { controller.nationalIDFile.value = File(''); }, icon: Icon(Icons.delete), ), ), ) : Container()), Visibility( visible: controller.nationalIDFile.value.path.trim() == '', child: CircularBlockButtonWidget( color: Get.theme.focusColor, text: Text( "Select".tr, style: Get.textTheme.bodyText2.copyWith( color: Colors.white, fontWeight: FontWeight.bold), ), onPressed: () async { showDialog( context: context, builder: (BuildContext context) => CupertinoAlertDialog( title: Text("National ID".tr), content: Text('Choose photo/file for your national ID'.tr), actions: [ CupertinoDialogAction( isDefaultAction: true, child: Text('Select from photos'.tr), onPressed: () async{ Navigator.pop(context); List<Asset> profilePic1 = <Asset>[].obs; await MultiImagePicker.pickImages( maxImages: 1, enableCamera: true, selectedAssets: profilePic1, cupertinoOptions: CupertinoOptions( takePhotoIcon: "chat", ), materialOptions: MaterialOptions( actionBarColor: "#339A58", statusBarColor: "#339A58", allViewTitle: "All Photos", useDetailsView: false, selectCircleStrokeColor: "#339A58", ), ).then((value) async { final filePath = await FlutterAbsolutePath.getAbsolutePath(value[0].identifier); File tempFile = File(filePath); if (tempFile.existsSync()) { File cropped = await ImageCropper.cropImage( sourcePath: tempFile.path, compressQuality: 100, compressFormat: ImageCompressFormat.jpg, androidUiSettings: AndroidUiSettings( toolbarColor: Get.theme.primaryColor, toolbarTitle: "Crop Image", statusBarColor: Colors.black, backgroundColor: Colors.white10, activeControlsWidgetColor: Get.theme.focusColor)); controller.nationalIDFile.value = cropped; } }); }, ), CupertinoDialogAction( isDefaultAction: true, child: Text('Select from files'.tr), onPressed: () async { Navigator.of(context).pop(); print('National ID File'); FilePickerResult result = await FilePicker.platform.pickFiles(); if (result != null) { controller.nationalIDFile.value = File(result.files.single.path); } else { // User canceled the picker } }, ), CupertinoDialogAction( isDefaultAction: true, child: Text('Cancel'.tr), onPressed: () async { Navigator.of(context).pop(); }, ) ], ), ); }, ).paddingSymmetric(horizontal: 50, vertical: 10), ), Text( 'Licence'.tr, // textAlign: TextAlign.left, style: Get.textTheme.bodyText2 .copyWith(fontWeight: FontWeight.bold), ).paddingOnly(top: 10, left: 20, right: 20, bottom: 10), // Container( // width: Get.width * 0.7, // height: Get.width * 0.5, // color: Colors.grey[100], // child: Center( // child: Icon( // Icons.photo, // size: 70, // )), // ).paddingSymmetric(horizontal: 50, vertical: 10), Obx(() => controller.licenceFile.value?.path != '' ? Card( elevation: 2, child: ListTile( title: Text( controller.licenceFile.value.path.substring( controller.licenceFile.value.path .lastIndexOf('/') + 1), style: TextStyle(color: Get.theme.focusColor), ), trailing: IconButton( onPressed: () { controller.licenceFile.value = File(''); }, icon: Icon(Icons.delete), ), ), ) : Container()), Visibility( visible: controller.licenceFile.value.path.trim() == '', child: CircularBlockButtonWidget( color: Get.theme.focusColor, text: Text( "Select".tr, style: Get.textTheme.bodyText2.copyWith( color: Colors.white, fontWeight: FontWeight.bold), ), onPressed: () async { showDialog( context: context, builder: (BuildContext context) => CupertinoAlertDialog( title: Text("License".tr), content: Text('Choose photo/file for your license'.tr), actions: [ CupertinoDialogAction( isDefaultAction: true, child: Text('Select from photos'.tr), onPressed: () async{ Navigator.pop(context); List<Asset> profilePic1 = <Asset>[].obs; await MultiImagePicker.pickImages( maxImages: 1, enableCamera: true, selectedAssets: profilePic1, cupertinoOptions: CupertinoOptions( takePhotoIcon: "chat", ), materialOptions: MaterialOptions( actionBarColor: "#339A58", statusBarColor: "#339A58", allViewTitle: "All Photos", useDetailsView: false, selectCircleStrokeColor: "#339A58", ), ).then((value) async { final filePath = await FlutterAbsolutePath.getAbsolutePath(value[0].identifier); File tempFile = File(filePath); if (tempFile.existsSync()) { File cropped = await ImageCropper.cropImage( sourcePath: tempFile.path, compressQuality: 100, compressFormat: ImageCompressFormat.jpg, androidUiSettings: AndroidUiSettings( toolbarColor: Get.theme.primaryColor, toolbarTitle: "Crop Image", statusBarColor: Colors.black, backgroundColor: Colors.white10, activeControlsWidgetColor: Get.theme.focusColor)); controller.licenceFile.value = cropped; } }); }, ), CupertinoDialogAction( isDefaultAction: true, child: Text('Select from files'.tr), onPressed: () async { Navigator.of(context).pop(); print('Licence File Selection'); FilePickerResult result = await FilePicker.platform.pickFiles( type: FileType.custom, allowedExtensions: [ 'jpg', 'pdf', 'png', 'jpeg', ], ); if (result != null) { controller.licenceFile.value = File(result.files.single.path); } else { // User canceled the picker } }, ), CupertinoDialogAction( isDefaultAction: true, child: Text('Cancel'.tr), onPressed: () async { Navigator.of(context).pop(); }, ) ], ), ); }, ).paddingOnly(left: 50, right: 50, top: 10, bottom: 30), ), ], ), ).paddingSymmetric(horizontal: 20)), CircularBlockButtonWidget( color: Get.theme.focusColor, text: Text( 'Save'.tr, style: Get.textTheme.bodyText2 .copyWith(color: Colors.white, fontWeight: FontWeight.bold), // TextStyle( // color: Colors.white, // fontWeight: FontWeight.bold, // fontSize: Get.textTheme.headline4.fontSize), ), onPressed: () async { if (controller.bankID == -1) { Get.showSnackbar(Ui.ErrorSnackBar( title: "Failed".tr, message: "please select the bank".tr, )); return; } if (controller.supplierCode == null) { print("1"); if (_loginForm.currentState.validate()) { if (controller.nationalIDFile.value.path.trim() == '') { Get.showSnackbar(Ui.ErrorSnackBar( title: "Failed".tr, message: "enterNationalFile".tr, )); return; } if (controller.licenceFile.value.path.trim() == '') { Get.showSnackbar(Ui.ErrorSnackBar( title: "Failed".tr, message: "enterLicenseFile".tr, )); return; } List<UploadSupplierDocument> docsList = <UploadSupplierDocument>[]; UploadSupplierDocument nationalData = UploadSupplierDocument( filePath: controller.nationalIDFile.value.path, fileType: 4, fileName: controller.nationalIDFile.value.path .substring(controller.licenceFile.value.path .lastIndexOf('/') + 1)); UploadSupplierDocument licenceData = UploadSupplierDocument( filePath: controller.licenceFile.value.path, fileType: 1, fileName: controller.licenceFile.value.path.substring( controller.licenceFile.value.path.lastIndexOf('/') + 1)); docsList.add(nationalData); docsList.add(licenceData); AddSupplierDto addSupplierDto = AddSupplierDto( supplierName: controller.currentUser.appUser.value.name, email: controller.currentUser.appUser.value.email, mobile: controller.currentUser.appUser.value.phoneNumber, commissionValue: 0, commissionPercentage: 10, depositTerms: "Daily", bankId: controller.bankID, bankAccountHolderName: controller.bankNameFromList.value, bankAccount: controller.accountNumber.value.text.toString(), iban: controller.iBANNumber.value.text.toString(), isActive: true, ); Get.dialog( Center( child: CircularProgressIndicator( valueColor: AlwaysStoppedAnimation<Color>( Get.theme.accentColor, ), ), ), barrierDismissible: true, ); await ApiProvider(httpClient: Dio()).addSupplierFromReg( addSupplierDto, docsList, controller.currentUser.appUser.value.id, controller); } } else { print("sf"); if (controller.nationalIDFile.value.path.trim() == '') { Get.showSnackbar(Ui.ErrorSnackBar( title: "Failed".tr, message: "enterNationalFile".tr, )); return; } if (controller.licenceFile.value.path.trim() == '') { Get.showSnackbar(Ui.ErrorSnackBar( title: "Failed".tr, message: "enterLicenseFile".tr, )); return; } List<UploadSupplierDocument> docsList = <UploadSupplierDocument>[]; UploadSupplierDocument nationalData = UploadSupplierDocument( filePath: controller.nationalIDFile.value.path, fileType: 4, fileName: controller.nationalIDFile.value.path.substring( controller.licenceFile.value.path.lastIndexOf('/') + 1)); UploadSupplierDocument licenceData = UploadSupplierDocument( filePath: controller.licenceFile.value.path, fileType: 1, fileName: controller.licenceFile.value.path.substring( controller.licenceFile.value.path.lastIndexOf('/') + 1)); docsList.add(nationalData); docsList.add(licenceData); Get.dialog( Center( child: CircularProgressIndicator( valueColor: AlwaysStoppedAnimation<Color>( Get.theme.accentColor, ), ), ), barrierDismissible: true, ); await ApiProvider(httpClient: Dio()) .uploadSupllierDocsFromReg( docsList, controller.supplierCode, controller.currentUser.appUser.value.id, controller); } }, ).paddingSymmetric(horizontal: 50, vertical: 20), Visibility( visible: controller.supplierCode == null, child: CircularBlockButtonWidget( color: Colors.grey, text: Text( 'Skip'.tr, style: Get.textTheme.bodyText2.copyWith( color: Colors.white, fontWeight: FontWeight.bold), ), onPressed: () async { Get.offAllNamed(Routes.PHONE_VERIFICATION); }, ).paddingSymmetric(horizontal: 50, vertical: 5), ), SizedBox( height: 15.0, ) ], )), ), ); } } class payment_textFormFeild extends StatelessWidget { const payment_textFormFeild( {Key key, @required this.controllerText, this.hintTxt, this.validator, this.labelTxt}) : super(key: key); final TextEditingController controllerText; final String hintTxt; final String labelTxt; final Function validator; @override Widget build(BuildContext context) { return TextFormField( validator: validator, controller: controllerText, cursorColor: Colors.black87, style: TextStyle( color: Colors.black87, ), decoration: InputDecoration( enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: Get.theme.hintColor), ), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: Get.theme.hintColor.withOpacity(0.3)), ), hintText: hintTxt.tr, label: Text(labelTxt.tr), labelStyle: Get.textTheme.subtitle2, hintStyle: TextStyle( color: Get.theme.hintColor, ), ), ).paddingSymmetric(horizontal: 20, vertical: 25); } }
Editor is loading...