image_picker_gallery_camera 0.3.0 image_picker_gallery_camera: ^0.3.0 copied to clipboard
Flutter Package to Pick Image From Gallery or Camera. This Package supports picking image from Camera,Gallery and Both Camera abd Gallery.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker_gallery_camera/image_picker_gallery_camera.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Example Image Picker',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Example Image Picker'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var _image;
Future getImage(ImgSource source) async {
var image = await ImagePickerGC.pickImage(
enableCloseButton: true,
closeIcon: Icon(
Icons.close,
color: Colors.red,
size: 12,
),
context: context,
source: source,
barrierDismissible: true,
cameraIcon: Icon(
Icons.camera_alt,
color: Colors.red,
), //cameraIcon and galleryIcon can change. If no icon provided default icon will be present
cameraText: Text(
"From Camera",
style: TextStyle(color: Colors.red),
),
galleryText: Text(
"From Gallery",
style: TextStyle(color: Colors.blue),
));
setState(() {
_image = image;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 300,
child: ElevatedButton(
onPressed: () => getImage(ImgSource.Gallery),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: Text(
"From Gallery".toUpperCase(),
style: TextStyle(color: Colors.white),
),
),
),
Container(
width: 300,
child: ElevatedButton(
onPressed: () => getImage(ImgSource.Camera),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.deepPurple,
),
child: Text(
"From Camera".toUpperCase(),
style: TextStyle(color: Colors.white),
),
),
),
Container(
width: 300,
child: ElevatedButton(
onPressed: () => getImage(ImgSource.Both),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
),
child: Text(
"Both".toUpperCase(),
style: TextStyle(color: Colors.white),
),
),
),
_image != null ? Image.file(File(_image.path)) : Container(),
],
),
),
),
);
}
}