0

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"))
          ],
        ))));
  }
}
Tarun Binwal
  • 43
  • 1
  • 11
  • Does this answer your question? [How do I determine the width and height of an image in Flutter?](https://stackoverflow.com/questions/44665955/how-do-i-determine-the-width-and-height-of-an-image-in-flutter) – Tokenyet Mar 27 '20 at 05:57
  • No sir actually i want to know the height and width of the image which i will fetch from the gallery, sir i am not sure that your suggested answer will work actually i am new i flutter its been one month iam working on this ........sir your suggestion is somewhat simiilar but i am not abel to understand it can you help please sir clearfying it – Tarun Binwal Mar 27 '20 at 07:07

0 Answers0