flutter_photokit 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 56

iOS PhotoKit Plugin for Flutter #

A Flutter plugin to interact with PhotoKit on iOS.

Usage #

To use this plugin, add flutter_photokit as a dependency in your pubspec.yaml file

Then, include the NSPhotoLibraryAddUsageDescription permission in your Info.plist

Example #

For an example on how to use this plugin, check out the sample app

For simplicity, the sample app just shows an example of saving a photo, but this plugin will work for videos as well! Usage is exactly the same.

0.1 #

  • Initial Release


import 'dart:async';
import 'dart:io';

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

import 'package:flutter_photokit/flutter_photokit.dart';
import 'package:path_provider/path_provider.dart';

enum _SaveStatus { NONE, SAVING, SAVED }

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

class MyApp extends StatefulWidget {
  const MyApp({Key key}) : super(key: key);

  _MyAppState createState() => new _MyAppState();

class _MyAppState extends State<MyApp> {
  _SaveStatus _cameraRollStatus = _SaveStatus.NONE;
  _SaveStatus _albumStatus = _SaveStatus.NONE;
  TextEditingController _albumTextController;

  static HttpClient _httpClient = HttpClient();
  static String _sampleImageUrl =
  // Use this link to test with a video.
  // static String _sampleVideoUrl = 'https://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4';

  void initState() {

    _albumTextController = TextEditingController()
      ..addListener(() => setState(() {}));

  Future<File> _downloadFile(String url) async {
    Uri uri = Uri.parse(url);

    HttpClientRequest req = await _httpClient.getUrl(uri);
    HttpClientResponse res = await req.close();

    List<int> bytes = await consolidateHttpClientResponseBytes(res);
    String tempDir = (await getTemporaryDirectory()).path;
    File outputFile = File('$tempDir/${uri.pathSegments.last}');
    await outputFile.writeAsBytes(bytes);

    return outputFile;

  void _saveToCameraRoll() async {
    setState(() => _cameraRollStatus = _SaveStatus.SAVING);

    File file = await _downloadFile(_sampleImageUrl);
    await FlutterPhotokit.saveToCameraRoll(filePath: file.path);

    setState(() => _cameraRollStatus = _SaveStatus.SAVED);

  void _saveToAlbum() async {
    setState(() => _albumStatus = _SaveStatus.SAVING);

    File file = await _downloadFile(_sampleImageUrl);
    await FlutterPhotokit.saveToAlbum(
        filePath: file.path, albumName: _albumTextController.value.text);

    setState(() => _albumStatus = _SaveStatus.SAVED);

  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
          appBar: new AppBar(
            title: const Text('Flutter PhotoKit Example'),
          body: _appBody()),

  Widget _appBody() {
    if (Platform.isIOS) {
      return SingleChildScrollView(
          child: new Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          SizedBox(height: 16.0),
          SizedBox(height: 16.0),
    } else {
      return Center(
          child: Text('The PhotoKit plugin is only available for iOS!'));

  Widget _saveToCameraRollRow() {
    switch (_cameraRollStatus) {
      case _SaveStatus.NONE:
        return RaisedButton(
            onPressed: _saveToCameraRoll, child: Text('Save to Camera Roll'));
      case _SaveStatus.SAVING:
        return CircularProgressIndicator();
      case _SaveStatus.SAVED:
        return Icon(Icons.check);

  Widget _saveToAlbumRow() {
    switch (_albumStatus) {
      case _SaveStatus.NONE:
        return Row(
          children: <Widget>[
              child: TextField(
                  controller: _albumTextController,
                  decoration: InputDecoration(labelText: 'Album name')),
              onPressed: _albumTextController.value.text.trim().isEmpty
                  ? null
                  : _saveToAlbum,
              child: Text('Save to album'),
      case _SaveStatus.SAVING:
        return CircularProgressIndicator();
      case _SaveStatus.SAVED:
        return Icon(Icons.check);

Use this package as a library

1. Depend on it

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

  flutter_photokit: ^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:flutter_photokit/flutter_photokit.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
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

Maintenance suggestions

Package is getting outdated. (-57.81 points)

The package was last published 82 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.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
path_provider 0.4.1