default_path_provider 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 83

default_path_provider #

default_path_provider is a flutter plugin that can provide you the path of android's default directories like Downloads, Pictures, DCIM, etc.

- Note: This plugin can work only in Android as of now!

Usage #

import 'package:default_path_provider/default_path_provider.dart';

String dirPath = await DefaultPathProvider.getDownloadDirectoryPath;

Available Methods #

  • getDownloadDirectoryPath
  • getPicturesDirectoryPath
  • getDCIMDirectoryPath
  • getNotificationsDirectoryPath
  • getMoviesDirectoryPath
  • getAlarmsDirectoryPath
  • getMusicDirectoryPath
  • getDocumentsDirectoryPath
  • getRingtonesDirectoryPath
  • getPodcastDirectoryPath

Contributing #

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update the tests as appropriate.

License #

MIT

0.1.0 #

  • Now you can get default directories path of android in your flutter app!

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';

import 'package:dio/dio.dart';
import 'package:default_path_provider/default_path_provider.dart';
import 'package:permission_handler/permission_handler.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _imageURL =
      "https://images.unsplash.com/photo-1497250681960-ef046c08a56e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=334&q=80";

  int _progress = 0;
  bool _isDownloading = false;

  ///Checking for storage permissions
  _checkPermission() async {
    PermissionStatus permission = await PermissionHandler()
        .checkPermissionStatus(PermissionGroup.storage);
    if (permission != PermissionStatus.granted) {
      Map<PermissionGroup, PermissionStatus> permissions =
          await PermissionHandler()
              .requestPermissions([PermissionGroup.storage]);
      if (permissions[PermissionGroup.storage] != PermissionStatus.granted) {
        exit(1);
      }
    }
  }

  ///starting download after getting path
  _startDownload(dir) async {
    Dio dio = Dio();
    try {
      await dio.download(_imageURL, "$dir/myimage.jpeg",
          onReceiveProgress: (rec, total) {
        setState(() {
          _progress = ((rec / total) * 100).toInt();
          if (_progress == 100) {
            if (this.mounted) {
              _isDownloading = false;
            }
          }
        });
      });
    } catch (e) {
      print(e);
      if (this.mounted) {
        setState(() {
          _isDownloading = false;
        });
      }
    }
  }

  ///Save the image to downloads directory
  _saveToDownloads() async {
    if (this.mounted) {
      setState(() {
        _isDownloading = true;
      });
    }
    var dir = await DefaultPathProvider.getDownloadDirectoryPath;
    _startDownload(dir);
  }

  ///Save the image to pictures directory
  _saveToPictures() async {
    if (this.mounted) {
      setState(() {
        _isDownloading = true;
      });
    }
    var dir = await DefaultPathProvider.getPicturesDirectoryPath;
    _startDownload(dir);
  }

  ///Save the image to DCIM directory
  _saveToDCIM() async {
    if (this.mounted) {
      setState(() {
        _isDownloading = true;
      });
    }
    var dir = await DefaultPathProvider.getDCIMDirectoryPath;
    _startDownload(dir);
  }

  ///Save the image to Notification directory
  _saveToNotifications() async {
    if (this.mounted) {
      setState(() {
        _isDownloading = true;
      });
    }
    var dir = await DefaultPathProvider.getNotificationsDirectoryPath;
    _startDownload(dir);
  }

  ///Save the image to Movies directory
  _saveToMovies() async {
    if (this.mounted) {
      setState(() {
        _isDownloading = true;
      });
    }
    var dir = await DefaultPathProvider.getMoviesDirectoryPath;
    _startDownload(dir);
  }

  ///Save the image to Alarm directory
  _saveToAlarms() async {
    if (this.mounted) {
      setState(() {
        _isDownloading = true;
      });
    }
    var dir = await DefaultPathProvider.getAlarmsDirectoryPath;
    _startDownload(dir);
  }

  ///Save the image to Music directory
  _saveToMusic() async {
    if (this.mounted) {
      setState(() {
        _isDownloading = true;
      });
    }
    var dir = await DefaultPathProvider.getMusicDirectoryPath;
    _startDownload(dir);
  }

  ///Save the image to documents directory
  _saveToDocuments() async {
    if (this.mounted) {
      setState(() {
        _isDownloading = true;
      });
    }
    var dir = await DefaultPathProvider.getDocumentsDirectoryPath;
    _startDownload(dir);
  }

  ///Save the image to ringtone directory
  _saveToRingtone() async {
    if (this.mounted) {
      setState(() {
        _isDownloading = true;
      });
    }
    var dir = await DefaultPathProvider.getRingtonesDirectoryPath;
    _startDownload(dir);
  }

  ///Save the image to podcast directory
  _saveToPodcast() async {
    if (this.mounted) {
      setState(() {
        _isDownloading = true;
      });
    }
    var dir = await DefaultPathProvider.getPodcastDirectoryPath;
    _startDownload(dir);
  }

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          body: SafeArea(
        child: _isDownloading
            ? Container(
                child: Center(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      CircularProgressIndicator(),
                      SizedBox(
                        height: 10.0,
                      ),
                      Text("Downloading..."),
                    ],
                  ),
                ),
              )
            : Container(
                padding: EdgeInsets.all(10.0),
                width: double.infinity,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Stack(
                      alignment: Alignment.center,
                      children: <Widget>[
                        CircularProgressIndicator(),
                        Padding(
                          padding: EdgeInsets.all(10.0),
                          child: ClipRRect(
                            child: Image.network(
                              _imageURL,
                              height: 200,
                              width: double.infinity,
                              fit: BoxFit.cover,
                            ),
                            borderRadius: BorderRadius.circular(10.0),
                          ),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 10.0,
                    ),
                    Expanded(
                      child: ListView(
                        children: <Widget>[
                          RaisedButton.icon(
                            onPressed: () => _saveToDownloads(),
                            label: Text("Save in Downloads"),
                            icon: Icon(Icons.file_download),
                          ),
                          RaisedButton.icon(
                            icon: Icon(Icons.camera_alt),
                            onPressed: () => _saveToDCIM(),
                            label: Text("Save in DCIM"),
                          ),
                          RaisedButton.icon(
                            icon: Icon(Icons.notifications),
                            onPressed: () => _saveToNotifications(),
                            label: Text("Save in Notification"),
                          ),
                          RaisedButton.icon(
                            icon: Icon(Icons.movie),
                            onPressed: () => _saveToMovies(),
                            label: Text("Save in Movies"),
                          ),
                          RaisedButton.icon(
                            icon: Icon(Icons.image),
                            onPressed: () => _saveToPictures(),
                            label: Text("Save in Pictures"),
                          ),
                          RaisedButton.icon(
                            icon: Icon(Icons.alarm),
                            onPressed: () => _saveToAlarms(),
                            label: Text("Save in Alarm"),
                          ),
                          RaisedButton.icon(
                            icon: Icon(Icons.library_music),
                            onPressed: () => _saveToMusic(),
                            label: Text("Save in Music"),
                          ),
                          RaisedButton.icon(
                            icon: Icon(Icons.assessment),
                            onPressed: () => _saveToDocuments(),
                            label: Text("Save in Document"),
                          ),
                          RaisedButton.icon(
                            icon: Icon(Icons.music_note),
                            onPressed: () => _saveToRingtone(),
                            label: Text("Save in Ringtone"),
                          ),
                          RaisedButton(
                            onPressed: () => _saveToPodcast(),
                            child: Text("Save in Podcast"),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
      )),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  default_path_provider: ^0.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:default_path_provider/default_path_provider.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
66
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]
83
Learn more about scoring.

We analyzed this package on Apr 7, 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

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