Untitled

 avatar
unknown
dart
3 years ago
15 kB
4
Indexable
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_absolute_path/flutter_absolute_path.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:image_cropper/image_cropper.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/modules/payment/controllers/payment_info_controller.dart';
import 'package:mobile/app/modules/payment/views/license_view.dart';
import 'package:mobile/app/modules/payment/widgets/page_step_container.dart';
import 'package:mobile/app/providers/api_provider.dart';
import 'package:mobile/common/ui.dart';
import 'package:multi_image_picker2/multi_image_picker2.dart';

class NationalIdView extends GetView<PaymentController> {
  int pageStep = 2;
  final PaymentController controller = Get.find();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Ui.parseColor("#F5F5F5"),
      appBar: AppBar(
        elevation: 0,
        backgroundColor: Colors.transparent,
        brightness: Brightness.light,
        iconTheme: new IconThemeData(color: Colors.black),
        title: Text(
          "Payment Info".tr,
          style: Get.theme.textTheme.headline4
              .copyWith(fontWeight: FontWeight.bold),
        ),
        centerTitle: true,
      ),
      body: Obx(
        () => Column(
          children: [
            Container(
              height: Get.height * 0.1,
              alignment: Alignment.center,
              child: Stack(
                children: [
                  Container(
                      alignment: Alignment.center,
                      width: Get.width * 0.8,
                      child: Divider(thickness: 1.0)),
                  Container(
                    width: Get.width * 0.8,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        PageStepContainer(
                          step: 1,
                          currentStep: pageStep,
                        ),
                        PageStepContainer(
                          step: 2,
                          currentStep: pageStep,
                        ),
                        PageStepContainer(
                          step: 3,
                          currentStep: pageStep,
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(
              height: 35.0,
            ),
            Container(
              padding:
                  EdgeInsets.only(top: 14, bottom: 14, left: 20, right: 20),
              margin: EdgeInsets.only(left: 40, right: 40),
              width: double.infinity,
              decoration: BoxDecoration(
                  color: Get.theme.primaryColor,
                  borderRadius: BorderRadius.vertical(top: Radius.circular(15)),
                  boxShadow: [
                    BoxShadow(
                        color: Get.theme.focusColor.withOpacity(0.1),
                        blurRadius: 10,
                        offset: Offset(0, 5)),
                  ],
                  border: Border.all(
                      color: Get.theme.focusColor.withOpacity(0.05))),
              alignment: Alignment.center,
              child: Text(
                "National Id".tr,
                style: Get.theme.textTheme.headline4.merge(
                  TextStyle(
                      color: Colors.black,
                      fontWeight: FontWeight.bold,
                      fontSize: 15),
                ),
              ),
            ),
            Container(
              padding:
                  EdgeInsets.only(top: 14, bottom: 14, left: 20, right: 20),
              margin: EdgeInsets.only(left: 40, right: 40),
              width: double.infinity,
              decoration: BoxDecoration(
                color: Get.theme.primaryColor,
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Icon(
                    Icons.info,
                    color: Get.theme.focusColor,
                  ),
                  SizedBox(
                    width: 10.0,
                  ),
                  Expanded(
                    child: Text(
                      "Upload clear image of National ID".tr,
                      style: Get.textTheme.headline4
                          .copyWith(fontWeight: FontWeight.bold),
                    ),
                  ),
                ],
              ),
            ),
            Container(
              padding:
                  EdgeInsets.only(top: 14, bottom: 14, left: 20, right: 20),
              margin: EdgeInsets.only(left: 40, right: 40),
              width: double.infinity,
              decoration: BoxDecoration(
                color: Get.theme.primaryColor,
              ),
              child: 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()),
            ),
            Container(
              padding:
                  EdgeInsets.only(top: 14, bottom: 14, left: 20, right: 20),
              margin: EdgeInsets.only(left: 40, right: 40),
              width: double.infinity,
              decoration: BoxDecoration(
                color: Get.theme.primaryColor,
              ),
              child: 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),
              ),
            ),
            Container(
              padding:
                  EdgeInsets.only(top: 14, bottom: 14, left: 20, right: 20),
              margin: EdgeInsets.only(left: 40, right: 40),
              width: double.infinity,
              decoration: BoxDecoration(
                  color: Get.theme.primaryColor,
                  borderRadius:
                      BorderRadius.vertical(bottom: Radius.circular(15)),
                  boxShadow: [
                    BoxShadow(
                        color: Get.theme.focusColor.withOpacity(0.1),
                        blurRadius: 10,
                        offset: Offset(0, 5)),
                  ],
                  border: Border.all(
                      color: Get.theme.focusColor.withOpacity(0.05))),
              alignment: Alignment.center,
              child: Container(
                width: Get.width,
                child: CircularBlockButtonWidget(
                  onPressed: () async {
                    if (controller.nationalIDFile.value.path.trim() == '') {
                      Get.showSnackbar(Ui.ErrorSnackBar(
                        title: "Failed".tr,
                        message: "enterNationalFile".tr,
                      ));
                      return;
                    }

                    UploadSupplierDocument nationalData =
                        UploadSupplierDocument(
                            filePath: controller.nationalIDFile.value.path,
                            fileType: 4,
                            fileName: controller.nationalIDFile.value.path
                                .substring(controller.licenceFile.value.path
                                        .lastIndexOf('/') +
                                    1));

                    Get.dialog(
                      Center(
                        child: CircularProgressIndicator(
                          valueColor: AlwaysStoppedAnimation<Color>(
                            Get.theme.accentColor,
                          ),
                        ),
                      ),
                      barrierDismissible: true,
                    );

                    await ApiProvider(httpClient: Dio())
                        .uploadSupllierDocsFromAccountSettings(
                            nationalData,
                            controller.currentUser.appUser.value.provider
                                .supplierCode,
                            controller.currentUser.appUser.value.id);

                    //  Get.to(LicenseView());
                  },
                  color: Get.theme.accentColor,
                  text: Text(
                    "Next".tr,
                    style: Get.theme.textTheme.headline5
                        .merge(TextStyle(color: Get.theme.primaryColor)),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
Editor is loading...