flutter_file_dialog 0.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 85

flutter_file_dialog #

Dialogs for picking and saving files in Android and in iOS.

Features #

  • Supports Android and iOS.
  • Modern plugin implementation based on Kotlin (Android) and Swift (iOS).
  • Pick image files and other documents.
  • Save a file to a selected location.
  • iOS dialog types: document and image.
  • iOS source types: camera, photo library, saved photos album.
  • Allow user to edit picked image in iOS.
  • Set file extension filter and mime types filter when picking a document.
  • Possibility to limit picking a file from the local device only (Android).

Examples #

Pick an image file #

  final params = OpenFileDialogParams(
    dialogType: OpenFileDialogType.image,
    sourceType: SourceType.photoLibrary,
  );
  final filePath = await FlutterFileDialog.pickFile(params: params);
  print(filePath);

Pick a document #

  final params = OpenFileDialogParams(
    dialogType: OpenFileDialogType,
    sourceType: SourceType.photoLibrary,
  );
  final filePath = await FlutterFileDialog.pickFile(params: params);
  print(filePath);

Save a file #

final params = SaveFileDialogParams(sourceFilePath: "path_of_file_to_save");
final filePath = await FlutterFileDialog.saveFile(params: params);
print(filePath);

0.0.5 #

[Android] Fixed: any thrown exception caused crash. Now exception is delivered correctly to caller.

0.0.4 #

  • [Android] Improved error handling.

0.0.3 #

  • [iOS] Use background threads where needed to keep UI more responsive.

0.0.2 #

  • Fixed a possible crash in apps using mixed Android V1/V2 embedding (issue #1)

0.0.1+1 #

  • Minor cleanup.

0.0.1 #

  • Initial release.

example/lib/main.dart

// Copyright (c) 2020 KineApps. All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_file_dialog/flutter_file_dialog.dart';

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

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

class _MyAppState extends State<MyApp> {
  bool _isBusy = false;
  OpenFileDialogType _dialogType = OpenFileDialogType.image;
  SourceType _sourceType = SourceType.photoLibrary;
  bool _allowEditing = false;
  File _currentFile;
  String _savedFilePath;
  bool _localOnly = false;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('FlutterFileDialog test app'),
        ),
        body: SingleChildScrollView(
          padding: const EdgeInsets.symmetric(horizontal: 8),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              const SizedBox(
                height: 24,
              ),
              CupertinoSegmentedControl<OpenFileDialogType>(
                children: {
                  OpenFileDialogType.document: Text("document"),
                  OpenFileDialogType.image: Text("image"),
                },
                groupValue: _dialogType,
                onValueChanged: (value) => setState(() => _dialogType = value),
              ),
              const SizedBox(
                height: 24,
              ),
              CupertinoSegmentedControl<SourceType>(
                children: {
                  SourceType.photoLibrary: Text("photoLibrary"),
                  SourceType.savedPhotosAlbum: Text("savedPhotosAlbum"),
                  SourceType.camera: Text("camera"),
                },
                groupValue: _sourceType,
                onValueChanged: (value) => setState(() => _sourceType = value),
              ),
              const SizedBox(
                height: 24,
              ),
              if (_dialogType == OpenFileDialogType.image)
                CheckboxListTile(
                  title: Text("Allow editing"),
                  value: _allowEditing,
                  onChanged: (v) => setState(() => _allowEditing = v),
                ),
              const SizedBox(
                height: 24,
              ),
              RaisedButton(
                child: Text('Pick file'),
                onPressed: () => _pickFile(),
              ),
              const SizedBox(
                height: 24,
              ),
              if (_currentFile?.existsSync() == true) ...[
                Text(_currentFile.path),
                Text(
                    "${(_currentFile.lengthSync() / 1024.0).toStringAsFixed(1)} KB"),
                SizedBox(
                  width: 200,
                  height: 200,
                  child: Image.file(
                    _currentFile,
                  ),
                ),
              ],
              RaisedButton(
                child: Text('Save file'),
                onPressed: _currentFile == null ? null : () => _saveFile(),
              ),
              Text(_savedFilePath ?? "-"),
              if (_isBusy) CircularProgressIndicator(),
              CheckboxListTile(
                title: Text("Local only"),
                value: _localOnly,
                onChanged: (v) => setState(() {
                  _localOnly = v;
                }),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Future<void> _pickFile() async {
    String result;
    try {
      setState(() {
        _isBusy = true;
        _currentFile = null;
      });
      final params = OpenFileDialogParams(
        dialogType: _dialogType,
        sourceType: _sourceType,
        allowEditing: _allowEditing,
        localOnly: _localOnly,
      );
      result = await FlutterFileDialog.pickFile(params: params);
      print(result);
    } on PlatformException catch (e) {
      print(e);
    } finally {
      setState(() {
        if (result != null) {
          _currentFile = File(result);
        } else {
          _currentFile = null;
        }
        _isBusy = false;
      });
    }
  }

  Future<void> _saveFile() async {
    String result;
    try {
      setState(() {
        _isBusy = true;
      });
      final params = SaveFileDialogParams(
          sourceFilePath: _currentFile.path, localOnly: _localOnly);
      result = await FlutterFileDialog.saveFile(params: params);
      print(result);
    } on PlatformException catch (e) {
      print(e);
    } finally {
      setState(() {
        _savedFilePath = result ?? _savedFilePath;
        _isBusy = false;
      });
    }
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_file_dialog: ^0.0.5

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_file_dialog/flutter_file_dialog.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
75
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
89
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

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

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

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.

The package description is too short. (-1 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 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