Code Monkey home page Code Monkey logo

ext_storage's Introduction

ext_storage

DEPRECATED this plugin

why?

ext_storage is minimal flutter plugin that provides external storage path and external public storage path.

https://pub.dev/packages/ext_storage

Features

NOTE This plugin is only supported Android.

ExtStorage package calls Android native code, Environment.getExternalStorageDirectory() and Environment.getExternalStoragePublicDirectory().

ExtStorage Andorid Native
ExtStorage.getExternalStorageDirectory() Environment.getExternalStorageDirectory()
ExtStorage.getExternalStoragePublicDirectory() Environment.getExternalStoragePublicDirectory()

ExtStorage.getExternalStoragePublicDirectory() needs Public Directory Type argument same as native getExternalStoragePublicDirectory().

ExtStorage Android Native
ExtStorage.DIRECTORY_MUSIC Environment.DIRECTORY_MUSIC
ExtStorage.DIRECTORY_PODCASTS Environment.DIRECTORY_PODCASTS
ExtStorage.DIRECTORY_RINGTONES Environment.DIRECTORY_RINGTONES
ExtStorage.DIRECTORY_ALARMS Environment.DIRECTORY_ALARMS
ExtStorage.DIRECTORY_NOTIFICATIONS Environment.DIRECTORY_NOTIFICATIONS
ExtStorage.DIRECTORY_PICTURES Environment.DIRECTORY_PICTURES
ExtStorage.DIRECTORY_MOVIES Environment.DIRECTORY_MOVIES
ExtStorage.DIRECTORY_DOWNLOADS Environment.DIRECTORY_DOWNLOADS
ExtStorage.DIRECTORY_DCIM Environment.DIRECTORY_DCIM
ExtStorage.DIRECTORY_DOCUMENTS Environment.DIRECTORY_DOCUMENTS
ExtStorage.DIRECTORY_SCREENSHOTS Environment.DIRECTORY_SCREENSHOTS
ExtStorage.DIRECTORY_AUDIOBOOKS Environment.DIRECTORY_AUDIOBOOKS

Installation

Add ext_storage as a dipendency in your project pubspeck.yaml.

dependencies:
  ext_storage:

and run the flutter pub get to install.

Usage

First, you write import ext_storage package.

import 'package:ext_storage/ext_storage.dart';

And you can call two functions.

void _example1() async {
  var path = await ExtStorage.getExternalStorageDirectory();
  print(path);  // /storage/emulated/0
}

void _example2() async {
  var path = await ExtStorage.getExternalStoragePublicDirectory(ExtStorage.DIRECTORY_PICTURES);
  print(path);  // /storage/emulated/0/Pictures
}

Author

yasukotelin

LICENCE

MIT LICENCE

ext_storage's People

Contributors

yasukotelin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ext_storage's Issues

Build failed due to gradle issues in plugin

Howdy mate!

I just touched down into your repo and wanted to use the plugin for getting Storage paths. Although unfortunately I ran into build error at gradle stage. Attached is the stacktrace from Flutter.

Launching lib\main.dart on Android SDK built for x86 in debug mode...
 lib\main.dart

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file 'C:\Users\mhetr\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\ext_storage-1.0.3\android\build.gradle' line: 25

* What went wrong:
A problem occurred evaluating project ':ext_storage'.
> Could not initialize class org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSetKt

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* Where:
Script 'C:\Users\mhetr\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 326

* What went wrong:
A problem occurred configuring project ':ext_storage'.
> Failed to notify project evaluation listener.
   > Could not initialize class org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSetKt
   > compileSdkVersion is not specified. Please add it to build.gradle

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

I have no good idea of why this happened - being new at Flutter, but maybe you could help fix if plugin issue or give some resolution if an error from my side.

I've added ext_storage: ^1.0.3 to my project, did a flutter get and ran a debug session.

Downloads directory is wrong

Thanks for the plugin!

However, the string value for DIRECTORY_DOWNLOADS is wrong, it should be Download (without the s). This makes files created in this directory not show up in the default download folder.

Unit testing with ext storage not feasible with Platform.isAndroid

https://github.com/yasukotelin/ext_storage/blob/master/lib/ext_storage.dart#L33-L46

Instead of using Platform.isAndroid to check if the current Platform is Android, I'm proposing the following solution:

import 'package:flutter/foundation.dart' show defaultTargetPlatform, TargetPlatform;

if (defaultTargetPlatform != TargetPlatform.android) {
    throw UnsupportedError("Only android supported");
}

This will making widget testing with ext_storage easier because in tests, Platform.isAndroid always returns false. Whereas with defaultTargetPlatform != TargetPlatform.android, a tester could use debugDefaultTargetPlatformOverride to determine if the test environment is Android vs iOS:

testWidgets('test Android', (WidgetTester tester) async {
    debugDefaultTargetPlatformOverride = TargetPlatform.android;
    // Insert Test Code Here
    debugDefaultTargetPlatformOverride = null;

I can submit a PR for this if you would like.

Build on Xcode 12.0.1 failing (swift compilation error)

flutterSDK/.pub-cache/hosted/pub.dartlang.org/ext_storage-1.0.3/ios/Classes/ExtStoragePlugin.m:2:9: fatal error: 'ext_storage/ext_storage-Swift.h' file not found
#import <ext_storage/ext_storage-Swift.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

image

image

Update the docs with the required permissions.

[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FileSystemException: Cannot open file, path = '/storage/emulated/0/Download/counter.txt' (OS Error: Permission denied, errno = 13)

iOS

How about directory for iOS.

ext_storage not run in IOS

  • ext_storage does not specify a Swift version and none of the targets (Runner) integrating it have the SWIFT_VERSION attribute set. Please contact the author or set the SWIFT_VERSION attribute in at least one of the targets that integrate this pod.
  • :c
    Captura de Pantalla 2021-04-14 a la(s) 10 20 01

Kotlin Gradle plugin version not satisfy

The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.10 and higher.
The following dependencies do not satisfy the required version:
project ':ext_storage' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71

I'm using Android Studio 3.5 and gradle 3.5.1.

Change the ext.kotlin_version to 1.3.10 and fixed the problem.

No such file or directory

Hello I'm using

ExtStorage.getExternalStoragePublicDirectory(ExtStorage.DIRECTORY_DOCUMENTS)

String fileDrc=await ExtStorage.getExternalStoragePublicDirectory(ExtStorage.DIRECTORY_DOCUMENTS);
final path= Directory( fileDrc+ "/Reports");

  if (!(await path.exists()))
    path.create();

but I get error

FileSystemException: Creation failed, path = '/storage/emulated/0/Documents/Reports' (OS Error: No such file or directory, errno = 2), stack trace: #0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.