Files
fcs/lib/pages/widgets/image_file_picker.dart

91 lines
2.7 KiB
Dart
Raw Normal View History

2020-10-16 21:38:39 +06:30
import 'dart:io';
import 'package:flutter/material.dart';
2021-09-10 14:25:37 +06:30
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
2020-10-16 21:38:39 +06:30
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 {
2021-09-10 14:25:37 +06:30
final OnFile? onFile;
2020-10-16 21:38:39 +06:30
2021-09-10 14:25:37 +06:30
const ImageFile({Key? key, this.onFile}) : super(key: key);
2020-10-16 21:38:39 +06:30
@override
_ImageFileState createState() => _ImageFileState();
}
class _ImageFileState extends State<ImageFile> {
2021-09-10 14:25:37 +06:30
File? selectedFile;
2020-10-16 21:38:39 +06:30
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.only(bottom: 20, top: 20),
child: new Wrap(
children: <Widget>[
new ListTile(
leading: CircleAvatar(
radius: 20,
backgroundColor: Colors.green,
child: Icon(MaterialIcons.insert_photo, color: Colors.white),
),
2020-10-20 18:45:18 +06:30
title: LocalText(context, "pm.gallery",
2020-10-16 21:38:39 +06:30
color: Colors.black87, fontSize: 15),
onTap: () async {
Navigator.pop(context);
selectedFile = await pickImage(ImageSource.gallery);
2021-09-10 14:25:37 +06:30
if (widget.onFile != null) widget.onFile!(selectedFile!);
2020-10-16 21:38:39 +06:30
}),
new ListTile(
leading: CircleAvatar(
backgroundColor: Colors.blue,
radius: 20,
child: Center(child: Icon(AntDesign.camera, color: Colors.white)),
),
2020-10-20 18:45:18 +06:30
title: LocalText(context, "pm.camera",
2020-10-16 21:38:39 +06:30
color: Colors.black87, fontSize: 15),
onTap: () async {
Navigator.pop(context);
selectedFile = await pickImage(ImageSource.camera);
2021-09-10 14:25:37 +06:30
if (widget.onFile != null) widget.onFile!(selectedFile!);
2020-10-16 21:38:39 +06:30
},
),
new ListTile(
leading: CircleAvatar(
backgroundColor: Colors.red,
radius: 20,
child: Icon(Icons.delete, color: Colors.white),
),
2020-10-20 18:45:18 +06:30
title: LocalText(context, "pm.remove_photo",
2020-10-16 21:38:39 +06:30
color: Colors.black87, fontSize: 15),
onTap: () {
Navigator.pop(context);
setState(() {
selectedFile = null;
});
2021-09-10 14:25:37 +06:30
if (widget.onFile != null) widget.onFile!(selectedFile!);
2020-10-16 21:38:39 +06:30
},
),
],
),
);
}
pickImage(ImageSource source) async {
var tempImage = await ImagePicker.pickImage(source: source);
return tempImage;
}
}