import 'package:car_for_her/config/palette.dart'; import 'package:car_for_her/singletons/profile_image.dart'; import 'package:flutter/material.dart'; import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:image_picker/image_picker.dart'; import 'package:badges/badges.dart'; class ProfileImagePicker extends StatefulWidget { const ProfileImagePicker({Key key}) : super(key: key); @override _ProfileImagePickerState createState() => _ProfileImagePickerState(); } class _ProfileImagePickerState extends State { ProfileImage profileImage = ProfileImage(); @override Widget build(BuildContext context) { return IconButton( onPressed: () async{ showMaterialModalBottomSheet( backgroundColor: Colors.white, context: context, builder: (context) => Container( child: Padding( padding: const EdgeInsets.all(22.0), child: Row( children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "Profile photo", style: TextStyle( color: Colors.black, fontFamily: 'MontserratSemiBold', 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 profileImage .pickImage(ImageSource .gallery); setState(() { imagePicked.image=profileImage.image; }); } else{ await profileImage .pickImage(ImageSource .gallery); setState(() { imagePicked.image=profileImage.image; }); } }, 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 profileImage .pickImage( ImageSource.camera); setState(() { imagePicked.image=profileImage.image; }); } else{ await profileImage .pickImage( ImageSource.camera); setState(() { imagePicked.image=profileImage.image; }); } }, child: Column( children: [ SvgPicture.asset( 'assets/icons/fromCamera.svg', height: 70, ), Text( "From Camera", style: TextStyle( fontFamily: 'MontserratExtraLight', fontSize: 14, fontWeight: FontWeight .bold), ) ], ), ), ], ) ], ), ], ), ), height: MediaQuery.of(context).size.height * 0.25, ), ); }, icon: Badge( position: BadgePosition.topEnd(top: 5, end: 5), badgeColor: Colors.white, borderSide: BorderSide(color: Colors.black), badgeContent: Icon( Icons.add, size: 10, color: Colors.black, ), child: Container( child: imagePicked.image != null ? Container( child: Center( child: ClipRRect( borderRadius: BorderRadius.circular(100), child: Container( width: double.maxFinite, height: double.maxFinite, child: Image.file( imagePicked.image, fit: BoxFit.fitWidth, )))), ) : Center( child: SvgPicture.asset( "assets/icons/camera.svg", fit: BoxFit.fill, )), height: 200, width: 200, decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), border: Border.all(color: Colors.black)), ), )); } }