Image Picker From Gallery Using Flutter Android App

admin_img Posted By Bajarangi soft , Posted On 27-11-2020

Image Picker is used to select image from device and set it to image widget.Almost every app will have to upload some images in terms of profile images and more.Now a days every social networking sites like facebook, instagram, whatsapp has the ability to choose a image from device and upload it to user dashboard.Not only images but videos, audio, documents all these data needs to be selected using a picker, providing the required formats for each file.

Image Picker From Gallery Using Flutter Android App

Image Picker From Gallery
Step 1 
We cannot directly remove the time stamp from Image Picker From Gallery but using the intl.dart package we can easily filter the date stamp from time stamp. So open your flutter project’s pubspec.yaml in code .

dependencies:
  flutter:
    sdk: flutter
  image_picker: ^0.6.7+14
Step 2
After done saving the pubspec.yaml file, Open your flutter project root folder in Command Prompt or Terminal and execute flutter pub get command. 

flutter pub get


Complete Code For Image Picker From Gallery In Flutter 
main.dart
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(

      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  File _image;

  Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.gallery);

    setState(() {
      _image = image;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        backgroundColor: Colors.deepOrangeAccent,
        title: new Text('Image Picker'),
      ),
      body: new Center(
        child: _image == null
            ? new Text('No image selected.')
            : new Image.file(_image),
      ),
      floatingActionButton: new FloatingActionButton(
        backgroundColor: Colors.deepOrangeAccent,
        onPressed: getImage,
        tooltip: 'Pick Image',
        child: new Icon(Icons.add_a_photo),
      ),
    );
  }
}

Related Post