import 'dart:io'; import 'package:car_for_her/config/palette.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:image_picker/image_picker.dart'; import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:toast/toast.dart'; class DriverValidation extends StatefulWidget { DriverValidation({Key key}) : super(key: key); @override _DriverValidationState createState() => _DriverValidationState(); } class _DriverValidationState extends State { File driverLicense; File vehicleRegistration; File vehicleInsurance; File driverID; @override Widget build(BuildContext context) { return GestureDetector( onTap: () { FocusScope.of(context).requestFocus(new FocusNode()); }, child: Scaffold( resizeToAvoidBottomInset: false, body: Container( child: Column( children: [ Center( child: Padding( padding: const EdgeInsets.fromLTRB(0, 60, 0, 0), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "Validation", style: TextStyle(fontFamily: 'MontHeavy', fontSize: 44), ), Container( margin: EdgeInsets.only(top: 25), width: double.maxFinite, height: 90, child: SvgPicture.asset( "assets/icons/checked.svg", ), ), Padding( padding: const EdgeInsets.fromLTRB(35, 35, 35, 0), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text( "Import photos", style: TextStyle( fontFamily: 'MontExtraLight', fontWeight: FontWeight.bold), ), Padding( padding: const EdgeInsets.only(top: 18.0), child: Form( child: Column( children: [ pickPhotoForm("Driver's license",driverLicense), pickPhotoForm("Vehicle registration",vehicleRegistration), pickPhotoForm("Vehicle insurance",vehicleInsurance), pickPhotoForm("Driver's ID",driverID), Container( margin: EdgeInsets.only(top: 30.0), width: 290, color: Palette.primary, child: TextButton( onPressed: () { if(driverID==null || driverLicense==null || vehicleInsurance==null || vehicleRegistration==null){ Toast.show("Please upload all required images", context, duration: Toast.LENGTH_LONG, gravity: Toast.TOP, backgroundColor: Color.fromRGBO(255, 0, 0, 0.7)); }else{ Navigator.pushNamed( context, '/driver_navigator'); } }, child: Text( "Done", style: TextStyle( color: Colors.white, fontFamily: 'MontExtraLight', fontWeight: FontWeight.bold, fontSize: 18), )), ) ], )), ), ], ), ), ], ), ), ), ], ), ), ), ); } Widget pickPhotoForm(String hintText,File imageFile) { Future pickImage(_imageSource) async { try { final image = await ImagePicker().pickImage(source: _imageSource); if (image == null) return; final imageTemporary = File(image.path); setState(() { if (hintText == "Driver's license") { driverLicense = imageTemporary; } else if (hintText == "Vehicle registration") { vehicleRegistration = imageTemporary; } else if (hintText == "Vehicle insurance") { vehicleInsurance = imageTemporary; } else if (hintText == "Driver's ID") { driverID = imageTemporary; } }); } on PlatformException catch (e) { print("failed : $e"); } } return Padding( padding: const EdgeInsets.only(bottom: 50), child: Container( child: Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(hintText, style: TextStyle( fontSize: 15, fontFamily: 'MontExtraLight', color: Color.fromRGBO(0, 0, 0, 0.5), fontWeight: FontWeight.bold)), GestureDetector( onTap: () { showMaterialModalBottomSheet( context: context, builder: (context) => Container( height: MediaQuery.of(context).size.height * 0.20, color: Colors.white, child: Padding( padding: const EdgeInsets.only(left: 18.0, top: 15), child: Row( children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "Profile photo", style: TextStyle( color: Colors.black, fontWeight: FontWeight.bold, fontFamily: 'MontExtraLight', fontSize: 18), ), SizedBox( height: 15, ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ GestureDetector( onTap: () async { var storageStatus = await Permission.storage.status; if (!storageStatus.isGranted) { await Permission.storage .request(); } await pickImage( ImageSource.gallery); }, child: Column( children: [ SvgPicture.asset( 'assets/icons/fromGallery.svg', height: 60, ), Text( "From gallery", style: TextStyle( fontFamily: 'MontserratExtraLight', fontSize: 14, fontWeight: FontWeight.bold), ) ], ), ), SizedBox( width: 40, ), GestureDetector( onTap: () async { var cameraStatus = await Permission.camera.status; if (!cameraStatus.isGranted) { await Permission.camera .request(); } await pickImage( ImageSource.camera); }, child: Column( children: [ SvgPicture.asset( 'assets/icons/fromCamera.svg', height: 70, ), Text( "From Camera", style: TextStyle( fontFamily: 'MontserratExtraLight', fontSize: 14, fontWeight: FontWeight.bold), ) ], ), ), ], ) ], ), ], ), ), ), ); }, child: SvgPicture.asset(imageFile==null? "assets/icons/camera.svg":"assets/icons/validate.svg", height: 20, )) ], ), SizedBox( height: 10, ), Container( height: 1, color: Color.fromRGBO(0, 0, 0, 0.3), width: double.maxFinite, ), ], ), ), ); } }