Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[path_provider] Use platform interface #2557

Merged
merged 38 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
807fbb4
Add dart file
franciscojma86 Feb 20, 2020
4748861
Rename file
franciscojma86 Feb 20, 2020
c40e813
add interface, rename files, add methods to class
franciscojma86 Feb 20, 2020
b049781
Add to method channel, not done
franciscojma86 Feb 20, 2020
7543c0c
Add dart file
franciscojma86 Feb 20, 2020
d4f1ba5
Rename file
franciscojma86 Feb 20, 2020
02b038a
Adds method channel test
franciscojma86 Feb 25, 2020
678dd5d
Remove prints
franciscojma86 Feb 25, 2020
d88af02
Fix imports and version
franciscojma86 Feb 25, 2020
70cffb0
Format and commentas
franciscojma86 Feb 25, 2020
9085967
Space
franciscojma86 Feb 25, 2020
290e166
Rename apis to path and provide only the string from the platform
franciscojma86 Feb 25, 2020
fcd271d
Add test and remove null
franciscojma86 Feb 25, 2020
0d7dbbd
Format
franciscojma86 Feb 25, 2020
8d9219a
Add export
franciscojma86 Feb 25, 2020
ee5bebb
Add imports
franciscojma86 Feb 25, 2020
2b1bbd9
Completed apis
franciscojma86 Feb 25, 2020
ea5904c
Fix and works
franciscojma86 Feb 25, 2020
689ac16
Improve tests
franciscojma86 Feb 26, 2020
7f7d351
Remove asyncs
franciscojma86 Feb 26, 2020
cdb863a
Add imports
franciscojma86 Feb 25, 2020
83fe162
Completed apis
franciscojma86 Feb 25, 2020
42cfa09
Fix and works
franciscojma86 Feb 25, 2020
90de093
Update version
franciscojma86 Feb 26, 2020
cdec1cb
Finish test
franciscojma86 Feb 26, 2020
1a22d7f
Merge branch 'path-implement' of github.com:franciscojma86/plugins in…
franciscojma86 Feb 26, 2020
c4e5c2e
Merge branch 'master' into path-implement
franciscojma86 Feb 26, 2020
d5355ad
Make results per test
franciscojma86 Feb 26, 2020
5550c74
Fix
franciscojma86 Feb 26, 2020
e544828
Add dependency
franciscojma86 Feb 26, 2020
6eba5a6
Merge branch 'master' into path-implement
franciscojma86 Feb 27, 2020
3098362
Fix typo nad enum
franciscojma86 Feb 28, 2020
c482f3c
Merge branch 'master' into path-implement
franciscojma86 Feb 28, 2020
d0afe4d
Change interface version
franciscojma86 Feb 28, 2020
c08013f
Address comments
franciscojma86 Feb 28, 2020
e1adebd
Remove mock call
franciscojma86 Feb 28, 2020
3aa1b5c
Typo and import
franciscojma86 Feb 29, 2020
a727550
Remove file
franciscojma86 Feb 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/path_provider/path_provider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.6.3

* Use `path_provider_platform_interface` in core plugin.

## 1.6.2

* Move package contents into `path_provider` for platform federation.
Expand Down

This file was deleted.

112 changes: 13 additions & 99 deletions packages/path_provider/path_provider/lib/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,12 @@
import 'dart:async';
import 'dart:io' show Directory;

import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
import 'package:platform/platform.dart';
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';

const MethodChannel _channel =
MethodChannel('plugins.flutter.io/path_provider');
export 'package:path_provider_platform_interface/path_provider_platform_interface.dart'
show StorageDirectory;

Platform _platform = const LocalPlatform();

/// This API is only exposed for the unit tests. It should not be used by
/// any code outside of the plugin itself.
@visibleForTesting
void setMockPathProviderPlatform(Platform platform) {
_platform = platform;
}
PathProviderPlatform get _platform => PathProviderPlatform.instance;

/// Path to the temporary directory on the device that is not backed up and is
/// suitable for storing caches of downloaded files.
Expand All @@ -33,8 +24,7 @@ void setMockPathProviderPlatform(Platform platform) {
///
/// On Android, this uses the `getCacheDir` API on the context.
Future<Directory> getTemporaryDirectory() async {
final String path =
await _channel.invokeMethod<String>('getTemporaryDirectory');
final String path = await _platform.getTemporaryPath();
if (path == null) {
return null;
}
Expand All @@ -52,8 +42,7 @@ Future<Directory> getTemporaryDirectory() async {
///
/// On Android, this function uses the `getFilesDir` API on the context.
Future<Directory> getApplicationSupportDirectory() async {
final String path =
await _channel.invokeMethod<String>('getApplicationSupportDirectory');
final String path = await _platform.getApplicationSupportPath();
if (path == null) {
return null;
}
Expand All @@ -67,11 +56,7 @@ Future<Directory> getApplicationSupportDirectory() async {
/// On Android, this function throws an [UnsupportedError] as no equivalent
/// path exists.
Future<Directory> getLibraryDirectory() async {
if (_platform.isAndroid) {
throw UnsupportedError('Functionality not available on Android');
}
final String path =
await _channel.invokeMethod<String>('getLibraryDirectory');
final String path = await _platform.getLibraryPath();
if (path == null) {
return null;
}
Expand All @@ -88,8 +73,7 @@ Future<Directory> getLibraryDirectory() async {
/// using [getExternalStorageDirectory] instead if data is intended to be visible
/// to the user.
Future<Directory> getApplicationDocumentsDirectory() async {
final String path =
await _channel.invokeMethod<String>('getApplicationDocumentsDirectory');
final String path = await _platform.getApplicationDocumentsPath();
if (path == null) {
return null;
}
Expand All @@ -105,11 +89,7 @@ Future<Directory> getApplicationDocumentsDirectory() async {
///
/// On Android this uses the `getExternalFilesDir(null)`.
Future<Directory> getExternalStorageDirectory() async {
if (_platform.isIOS) {
throw UnsupportedError('Functionality not available on iOS');
}
final String path =
await _channel.invokeMethod<String>('getStorageDirectory');
final String path = await _platform.getExternalStoragePath();
if (path == null) {
return null;
}
Expand All @@ -130,65 +110,11 @@ Future<Directory> getExternalStorageDirectory() async {
/// On Android this returns Context.getExternalCacheDirs() or
/// Context.getExternalCacheDir() on API levels below 19.
Future<List<Directory>> getExternalCacheDirectories() async {
if (_platform.isIOS) {
throw UnsupportedError('Functionality not available on iOS');
}
final List<String> paths =
await _channel.invokeListMethod<String>('getExternalCacheDirectories');
final List<String> paths = await _platform.getExternalCachePaths();

return paths.map((String path) => Directory(path)).toList();
}

/// Corresponds to constants defined in Androids `android.os.Environment` class.
///
/// https://developer.android.com/reference/android/os/Environment.html#fields_1
enum StorageDirectory {
/// Contains audio files that should be treated as music.
///
/// See https://developer.android.com/reference/android/os/Environment.html#DIRECTORY_MUSIC.
music,

/// Contains audio files that should be treated as podcasts.
///
/// See https://developer.android.com/reference/android/os/Environment.html#DIRECTORY_PODCASTS.
podcasts,

/// Contains audio files that should be treated as ringtones.
///
/// See https://developer.android.com/reference/android/os/Environment.html#DIRECTORY_RINGTONES.
ringtones,

/// Contains audio files that should be treated as alarm sounds.
///
/// See https://developer.android.com/reference/android/os/Environment.html#DIRECTORY_ALARMS.
alarms,

/// Contains audio files that should be treated as notification sounds.
///
/// See https://developer.android.com/reference/android/os/Environment.html#DIRECTORY_NOTIFICATIONS.
notifications,

/// Contains images. See https://developer.android.com/reference/android/os/Environment.html#DIRECTORY_PICTURES.
pictures,

/// Contains movies. See https://developer.android.com/reference/android/os/Environment.html#DIRECTORY_MOVIES.
movies,

/// Contains files of any type that have been downloaded by the user.
///
/// See https://developer.android.com/reference/android/os/Environment.html#DIRECTORY_DOWNLOADS.
downloads,

/// Used to hold both pictures and videos when the device filesystem is
/// treated like a camera's.
///
/// See https://developer.android.com/reference/android/os/Environment.html#DIRECTORY_DCIM.
dcim,

/// Holds user-created documents. See https://developer.android.com/reference/android/os/Environment.html#DIRECTORY_DOCUMENTS.
documents,
}

/// Paths to directories where application specific data can be stored.
/// These paths typically reside on external storage like separate partitions
/// or SD cards. Phones may have multiple storage directories available.
Expand All @@ -206,13 +132,8 @@ Future<List<Directory>> getExternalStorageDirectories({
/// how this type translates to Android storage directories.
StorageDirectory type,
}) async {
if (_platform.isIOS) {
throw UnsupportedError('Functionality not available on iOS');
}
final List<String> paths = await _channel.invokeListMethod<String>(
'getExternalStorageDirectories',
<String, dynamic>{'type': type?.index},
);
final List<String> paths =
await _platform.getExternalStoragePaths(type: type);

return paths.map((String path) => Directory(path)).toList();
}
Expand All @@ -223,14 +144,7 @@ Future<List<Directory>> getExternalStorageDirectories({
/// On Android and on iOS, this function throws an [UnsupportedError] as no equivalent
/// path exists.
Future<Directory> getDownloadsDirectory() async {
if (_platform.isAndroid) {
throw UnsupportedError('Functionality not available on Android');
}
if (_platform.isIOS) {
throw UnsupportedError('Functionality not available on iOS');
}
final String path =
await _channel.invokeMethod<String>('getDownloadsDirectory');
final String path = await _platform.getDownloadsPath();
if (path == null) {
return null;
}
Expand Down
7 changes: 4 additions & 3 deletions packages/path_provider/path_provider/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: path_provider
description: Flutter plugin for getting commonly used locations on the Android &
iOS file systems, such as the temp and app data directories.
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider
version: 1.6.2
version: 1.6.3

flutter:
plugin:
Expand All @@ -16,8 +16,7 @@ flutter:
dependencies:
flutter:
sdk: flutter
platform: ^2.0.0
meta: ^1.0.5
path_provider_platform_interface: ^1.0.1

dev_dependencies:
e2e: ^0.2.1
Expand All @@ -28,6 +27,8 @@ dev_dependencies:
test: any
uuid: "^1.0.0"
pedantic: ^1.8.0
mockito: ^4.1.1
plugin_platform_interface: ^1.0.0

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
Expand Down
Loading