I know how to fetch a image from the gallery but stuck in a part where i want to know how to fetch the information of the image which i am fetching for example i want to know the height and width of the image i am fetching.
If someone getting what i am trying to say please help thanks in advance. I have written a code just to fetch image and its below.
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
void main() {
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
File imageFile;
_openCamera(BuildContext context) async {
var picture = await ImagePicker.pickImage(source: ImageSource.camera);
this.setState(() {
imageFile = picture;
});
Navigator.of(context).pop();
}
_openGallery(BuildContext context) async {
var picture = await ImagePicker.pickImage(
source: ImageSource.gallery, maxHeight: 400, maxWidth: 400);
this.setState(() {
imageFile = picture;
});
Navigator.of(context).pop();
}
Future<void> _showChoiceDialog(BuildContext context) {
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Choose one"),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
GestureDetector(
child: Text("gallery"),
onTap: () {
_openGallery(context);
},
),
Padding(padding: EdgeInsets.all(10.0)),
GestureDetector(
child: Text("Camera"),
onTap: () {
_openCamera(context);
},
),
],
)),
);
});
}
Widget _DecideImageView() {
if (imageFile == null) {
return Text("Nothing to show");
} else {
return Image.file(
imageFile,
width: 400,
height: 400,
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Fetching Image"),
),
body: Container(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
_DecideImageView(),
Text(
"No Image Selected ",
style: TextStyle(fontWeight: FontWeight.bold),
),
RaisedButton(
onPressed: () {
_showChoiceDialog(context);
},
child: Text("Select Image"))
],
))));
}
}