file_picker_cross 2.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 96

file_picker_cross #

Select files on Android, iOS, the desktop and the web.

Getting Started #

file_picker_cross allows you to select files from your device and is compatible with Android, iOS, Desktops (using both go-flutter or FDE) and the web.

This package was realized using file_picker (Mobile platforms and go-flutter) and 'file_chooser' (Desktops). We only added compatibility to the web.

FilePickerCross FilePickerCross(
    type: FileTypeCross.any,                        // Available: `any`, `audio`, `image`, `video`, `custom`. Note: not available using FDE
    fileExtension: ''                               // Only if FileTypeCross.custom . May be any file extension like `.dot`, `.ppt,.pptx,.odp`
    );

Future<bool> pick()

String toString()

Uint8List toUint8List()

String toBase64()

MultipartFile toMultipartFile({String filename})

int get length

String get path // BETA: not working properly on Web and unoccasionally using go-flutter

Example:

    FilePickerCross filePicker = FilePickerCross();
    filePicker.pick().then((value) => setState(() {
          _filePath = filePicker.path;
          _fileLength = filePicker.toUint8List().lengthInBytes;
          try {
            // Only works for text files.
            _fileString = filePicker.toString();
          } catch (e) {
            _fileString =
                'Not a text file. Showing base64.\n\n' + filePicker.toBase64();
          }
        }));
  }

What do go-flutter and FDE mean? #

Flutter initially only supported Android and iOS. To add support for desktop platforms, some people started the go-flutter providing Flutter applications on Windows, Linux and macOS using the Go language.

Later, Flutter itself announced desktop support (FDE) but still, it's not stable yet.

We try to support both as much as possible.

Web #

Of cause, it requires Flutter to be set up for web development.

Set up Flutter for Web

All Desktop platforms #

Of cause, it requires Flutter to be set up for your platform.

Set up go-flutter Set up FDE

Mobile platforms #

No setup required 🎉.

macOS (using FDE) #

You will need to add an entitlement for either read-only access:

	<key>com.apple.security.files.user-selected.read-only</key>
	<true/>

or read/write access:

	<key>com.apple.security.files.user-selected.read-write</key>
	<true/>

depending on your use case.

Linux (using FDE) #

This plugin requires the following libraries:

  • GTK 3
  • pkg-config

Installation example for debian-based systems:

sudo apt-get install libgtk-3-dev pkg-config

Moreover, you will need to update main.cc to include the GTK initialization and runloop changes shown in the testbed example.

  1. Delete your existing linux directory (make sure you know any manual modification you did): rm -rf linux
  2. Copy the testbed/{gtk,linux} subdirectory of this projects's example/ into your project.

2.1.0 #

  • Implemented String get path (#1, #5, #6)

2.0.0 #

  • Added support for Flutter's official Desktop runtime (FDE)

1.2.0 #

  • Fixed crashes on io-Devices (Desktop, Android, iOS) if the fileExtension is empty

1.1.0 #

  • Fixed compatibility issues for Android and iOS

1.0.0 #

  • Basic functionality working on the web

example/lib/main.dart

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

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

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

class _MyAppState extends State<MyApp> {
  FilePickerCross filePicker = FilePickerCross();

  String _fileString;
  int _fileLength = 0;
  String _filePath;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: ListView(
          padding: EdgeInsets.all(8),
          children: <Widget>[
            RaisedButton(
              onPressed: _selectFile,
              child: Text('Select File'),
            ),
            Text('File path: $_filePath (Might cause issues on web)\n'),
            Text('File length: $_fileLength\n'),
            Text('File as String: $_fileString\n'),
          ],
        ),
      ),
    );
  }

  void _selectFile() {
    filePicker.pick().then((value) => setState(() {
        _filePath = filePicker.path;
          _fileLength = filePicker.toUint8List().lengthInBytes;
          try {
            _fileString = filePicker.toString();
          } catch (e) {
            _fileString =
                'Not a text file. Showing base64.\n\n' + filePicker.toBase64();
          }
        }));
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  file_picker_cross: ^2.1.0

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:file_picker_cross/file_picker_cross.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
91
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]
96
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform android

Because:

  • package:file_picker_cross/file_picker_cross.dart that imports:
  • package:file_picker_cross/file_picker_io.dart that imports:
  • package:file_chooser/file_chooser.dart that declares support for platforms: windows, linux, macos

Package does not support Flutter platform ios

Because:

  • package:file_picker_cross/file_picker_cross.dart that imports:
  • package:file_picker_cross/file_picker_io.dart that imports:
  • package:file_chooser/file_chooser.dart that declares support for platforms: windows, linux, macos

Package does not support Flutter platform linux

Because:

  • package:file_picker_cross/file_picker_cross.dart that imports:
  • package:file_picker_cross/file_picker_io.dart that imports:
  • package:file_picker/file_picker.dart that declares support for platforms: android, ios, web

Package does not support Flutter platform macos

Because:

  • package:file_picker_cross/file_picker_cross.dart that imports:
  • package:file_picker_cross/file_picker_io.dart that imports:
  • package:file_picker/file_picker.dart that declares support for platforms: android, ios, web

Package does not support Flutter platform windows

Because:

  • package:file_picker_cross/file_picker_cross.dart that imports:
  • package:file_picker_cross/file_picker_io.dart that imports:
  • package:file_picker/file_picker.dart that declares support for platforms: android, ios, web

Package not compatible with SDK dart

Because:

  • file_picker_cross that is a package requiring null.

Health suggestions

Format lib/file_picker_cross.dart.

Run flutter format to format lib/file_picker_cross.dart.

Format lib/file_picker_io.dart.

Run flutter format to format lib/file_picker_io.dart.

Format lib/file_picker_stub.dart.

Run flutter format to format lib/file_picker_stub.dart.

Format lib/file_picker_web.dart.

Run flutter format to format lib/file_picker_web.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
file_chooser ^0.1.3 0.1.3
file_picker ^1.6.3 1.12.0
flutter 0.0.0
http ^0.12.0+4 0.12.1
http_parser ^3.1.3 3.1.4
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
file_picker_platform_interface 1.2.0
flutter_plugin_android_lifecycle 1.0.8
meta 1.1.8 1.2.1
path 1.7.0
pedantic 1.9.0 1.9.1
plugin_platform_interface 1.0.2
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test