import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_icons/flutter_icons.dart'; import 'package:image_picker/image_picker.dart'; import 'local_text.dart'; typedef OnFile = void Function(File); modelBottomSheet(BuildContext context, {final OnFile onFile}) { showModalBottomSheet( elevation: 10, backgroundColor: Colors.white, context: context, builder: (BuildContext context) { return ImageFile(onFile: onFile); }); } class ImageFile extends StatefulWidget { final OnFile onFile; const ImageFile({Key key, this.onFile}) : super(key: key); @override _ImageFileState createState() => _ImageFileState(); } class _ImageFileState extends State { File selectedFile; @override Widget build(BuildContext context) { return Container( padding: EdgeInsets.only(bottom: 20, top: 20), child: new Wrap( children: [ new ListTile( leading: CircleAvatar( radius: 20, backgroundColor: Colors.green, child: Icon(MaterialIcons.insert_photo, color: Colors.white), ), title: LocalText(context, "pm.gallery", color: Colors.black87, fontSize: 15), onTap: () async { Navigator.pop(context); selectedFile = await pickImage(ImageSource.gallery); if (widget.onFile != null) widget.onFile(selectedFile); }), new ListTile( leading: CircleAvatar( backgroundColor: Colors.blue, radius: 20, child: Center(child: Icon(AntDesign.camera, color: Colors.white)), ), title: LocalText(context, "pm.camera", color: Colors.black87, fontSize: 15), onTap: () async { Navigator.pop(context); selectedFile = await pickImage(ImageSource.camera); if (widget.onFile != null) widget.onFile(selectedFile); }, ), new ListTile( leading: CircleAvatar( backgroundColor: Colors.red, radius: 20, child: Icon(Icons.delete, color: Colors.white), ), title: LocalText(context, "pm.remove_photo", color: Colors.black87, fontSize: 15), onTap: () { Navigator.pop(context); setState(() { selectedFile = null; }); if (widget.onFile != null) widget.onFile(selectedFile); }, ), ], ), ); } pickImage(ImageSource source) async { var tempImage = await ImagePicker.pickImage(source: source); return tempImage; } }