flutter_document_picker 0.1.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 95

flutter_document_picker #

Allows user pick a document.

In Android Intent.ACTION_OPEN_DOCUMENT is used. This intent is supported only from Android 19 (KitKat) SDK version. When file is picked its extension is checked using androidFileExtension parameter. Then file is copied to app cache directory by using TaskAsyncLoader. Copied file path is returned as result. If picked file extension mismatch extension provided by parameter extension_mismatch error is returned.

In iOS UIDocumentPickerViewController is used. Files can be filtered by UTI type using iosUtiType parameter. Picked file path is returned as result.

Params #

Plugin has two optional parameters to pick only specific document type: iosUtiType and androidFileExtension.

  • String iosUtiType (used only in iOS)

    In iOS Uniform Type Identifiers is used to check document types. If value is null "public.data" document type will be provided.

    More info: https://developer.apple.com/library/archive/qa/qa1587/_index.html

  • String androidFileExtension (used only in Android)

    In android file extension will be checked. If value is null - picked document extension will not be checked.

Example #

//Without parameters:
final path = await FlutterDocumentPicker.openDocument();
  
  ...

    
//With parameters:
FlutterDocumentPickerParams params = FlutterDocumentPickerParams(      
  androidFileExtension: "mwfbak",
  iosUtiType: "com.sidlatau.example.mwfbak",
);

final path = await FlutterDocumentPicker.openDocument(params: params);

Getting Started #

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

0.0.1 #

  • Initial version that works on Android and iOS. Has ability to filter file to pick by extension.

0.0.2 #

  • Fixed documentation.

0.0.3 #

  • Removed print statements.

0.1.0 #

  • iOS part: picked document is copied to temp dir.

0.1.1 #

  • Android part: removed.

example/lib/main.dart

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

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

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

class _MyAppState extends State<MyApp> {
  String _path = '-';
  bool _pickFileInProgress = false;
  bool _iosPublicDataUTI = true;
  bool _checkByCustomExtension = false;

  final _utiController = TextEditingController(
    text: 'com.sidlatau.example.mwfbak',
  );

  final _extensionController = TextEditingController(
    text: 'mwfbak',
  );

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.open_in_new),
              onPressed: _pickFileInProgress ? null : _pickDocument,
            )
          ],
        ),
        body: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  'Picked file path:',
                  style: Theme.of(context).textTheme.title,
                ),
                Text('$_path'),
                _pickFileInProgress ? CircularProgressIndicator() : Container(),
                Theme.of(context).platform == TargetPlatform.iOS
                    ? _buildIOSParams()
                    : _buildAndroidParams(),
              ],
            ),
          ),
        ),
      ),
    );
  }

  _pickDocument() async {
    String result;
    try {
      setState(() {
        _path = '-';
        _pickFileInProgress = true;
      });

      FlutterDocumentPickerParams params = FlutterDocumentPickerParams(
        androidFileExtension:
            _checkByCustomExtension ? _extensionController.text : null,
        iosUtiType: _iosPublicDataUTI ? null : _utiController.text,
      );

      result = await FlutterDocumentPicker.openDocument(params: params);
    } catch (e) {
      result = 'Error: $e';
    } finally {
      setState(() {
        _pickFileInProgress = false;
      });
    }

    setState(() {
      _path = result;
    });
  }

  _buildIOSParams() {
    return Padding(
      padding: EdgeInsets.only(top: 24.0),
      child: Card(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(bottom: 16.0),
                child: Text(
                  'iOS Params',
                  style: Theme.of(context).textTheme.headline,
                ),
              ),
              Text(
                'Example app is configured to pick custom document type with extension ".mwfbak"',
                style: Theme.of(context).textTheme.body1,
              ),
              Row(
                children: <Widget>[
                  Expanded(
                    child: Text(
                      'Allow pick all documents("public.data" UTI will be used).',
                      softWrap: true,
                    ),
                  ),
                  Checkbox(
                    value: _iosPublicDataUTI,
                    onChanged: (value) {
                      setState(() {
                        _iosPublicDataUTI = value;
                      });
                    },
                  ),
                ],
              ),
              TextField(
                controller: _utiController,
                enabled: !_iosPublicDataUTI,
                decoration: InputDecoration(
                  border: OutlineInputBorder(),
                  labelText: 'Uniform Type Identifier to pick:',
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  _buildAndroidParams() {
    return Padding(
      padding: EdgeInsets.only(top: 24.0),
      child: Card(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(bottom: 16.0),
                child: Text(
                  'Android Params',
                  style: Theme.of(context).textTheme.headline,
                ),
              ),
              Row(
                children: <Widget>[
                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.only(bottom: 16.0),
                      child: Text(
                        'Check file by extension - if picked file does not have wantent extension - return "extension_mismatch" error',
                        softWrap: true,
                      ),
                    ),
                  ),
                  Checkbox(
                    value: _checkByCustomExtension,
                    onChanged: (value) {
                      setState(() {
                        _checkByCustomExtension = value;
                      });
                    },
                  ),
                ],
              ),
              TextField(
                controller: _extensionController,
                enabled: _checkByCustomExtension,
                decoration: InputDecoration(
                  border: OutlineInputBorder(),
                  labelText: 'File extension to pick:',
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_document_picker: ^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_document_picker/flutter_document_picker.dart';
  
Version Uploaded Documentation Archive
3.0.0 May 5, 2019 Go to the documentation of flutter_document_picker 3.0.0 Download flutter_document_picker 3.0.0 archive
2.0.0 Feb 25, 2019 Go to the documentation of flutter_document_picker 2.0.0 Download flutter_document_picker 2.0.0 archive
1.4.0 Jan 22, 2019 Go to the documentation of flutter_document_picker 1.4.0 Download flutter_document_picker 1.4.0 archive
1.3.0 Jan 9, 2019 Go to the documentation of flutter_document_picker 1.3.0 Download flutter_document_picker 1.3.0 archive
1.2.0 Dec 8, 2018 Go to the documentation of flutter_document_picker 1.2.0 Download flutter_document_picker 1.2.0 archive
1.1.3 Oct 19, 2018 Go to the documentation of flutter_document_picker 1.1.3 Download flutter_document_picker 1.1.3 archive
1.1.2 Oct 8, 2018 Go to the documentation of flutter_document_picker 1.1.2 Download flutter_document_picker 1.1.2 archive
1.1.1 Sep 28, 2018 Go to the documentation of flutter_document_picker 1.1.1 Download flutter_document_picker 1.1.1 archive
1.1.0 Sep 22, 2018 Go to the documentation of flutter_document_picker 1.1.0 Download flutter_document_picker 1.1.0 archive
1.0.1 Sep 14, 2018 Go to the documentation of flutter_document_picker 1.0.1 Download flutter_document_picker 1.0.1 archive

All 16 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
90
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
95
Learn more about scoring.

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

  • Dart: 2.3.0
  • pana: 0.12.15
  • Flutter: 1.5.8

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

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
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8