start_image_picker 0.0.1+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 52

Image Picker plugin for Flutter #

A better Flutter plugin for iOS and Android for picking images from the image library, and taking new pictures with the camera.

Note: This plugin is still under development, and some APIs might not be available yet.

iOS #

Add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:

  • NSPhotoLibraryUsageDescription - describe why your app needs permission for the photo library. This is called Privacy - Photo Library Usage Description in the visual editor.
  • NSCameraUsageDescription - describe why your app needs access to the camera. This is called Privacy - Camera Usage Description in the visual editor.
  • NSMicrophoneUsageDescription - describe why your app needs access to the microphone, if you intend to record videos. This is called Privacy - Microphone Usage Description in the visual editor.

Android #

Not available yet.

Example #

import 'package:start_image_picker/start_image_picker.dart';

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

class _MyHomePageState extends State<MyHomePage> {
  File _image;

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

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

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

0.0.1+1 #

  • Initial Release.

example/lib/main.dart

import 'dart:io' show File;

import 'package:flutter/material.dart';
import 'package:start_image_picker/start_image_picker.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  File _imageFromCamera;
  File _imageFromGallery;
  File _videoFromCamera;
  File _videoFromGallery;
  int _selectedIndex = 0;

  void _pickImageFromCamera() async {
    final file = await ImagePicker.pickImage(
      source: ImageSource.camera,
    );
    setState(() {
      _imageFromCamera = file;
    });
  }

  void _pickImageFromGallery() async {
    final file = await ImagePicker.pickImage(
      source: ImageSource.photoLibrary,
    );
    setState(() {
      _imageFromGallery = file;
    });
  }

  void _pickVideoFromCamera() async {
    final file = await ImagePicker.pickVideo(
      source: ImageSource.camera,
    );
    setState(() {
      _videoFromCamera = file;
    });
  }

  void _pickVideoFromGallery() async {
    final file = await ImagePicker.pickVideo(
      source: ImageSource.photoLibrary,
    );
    setState(() {
      _videoFromGallery = file;
    });
  }

  void _onNavigationBarTap(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: _selectedIndex,
          onTap: _onNavigationBarTap,
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Icon(Icons.camera),
              title: Text('Camera'),
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.panorama),
              title: Text('Gallery'),
            ),
          ],
        ),
        body: _selectedIndex < 1 ? _camera() : _gallery(),
      ),
    );
  }

  Widget _camera() {
    return Column(
      children: <Widget>[
        Expanded(
          child: (_imageFromCamera != null)
              ? Image.file(_imageFromCamera)
              : Container(),
        ),
        FlatButton(
          onPressed: _pickImageFromCamera,
          child: Text('Pick from camera'),
        ),
        Expanded(
          child: (_imageFromGallery != null)
              ? Image.file(_imageFromGallery)
              : Container(),
        ),
        FlatButton(
          onPressed: _pickImageFromGallery,
          child: Text('Pick from camera'),
        ),
      ],
    );
  }

  Widget _gallery() {
    return Column(
      children: <Widget>[
        Expanded(
          child: (_videoFromCamera?.path != null)
              ? Text(_videoFromCamera?.path)
              : Container(),
        ),
        FlatButton(
          onPressed: _pickVideoFromCamera,
          child: Text('Pick from camera'),
        ),
        Expanded(
          child: (_videoFromGallery?.path != null)
              ? Text(_videoFromGallery?.path)
              : Container(),
        ),
        FlatButton(
          onPressed: _pickVideoFromGallery,
          child: Text('Pick from camera'),
        )
      ],
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  start_image_picker: ^0.0.1+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:start_image_picker/start_image_picker.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
8
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
52
Learn more about scoring.

We analyzed this package on Apr 4, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

15 out of 15 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test