Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions packages/path_provider/path_provider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.0-nullsafety.2

* Removed pre-screening for platform.
* Updated tests accordingly.

## 2.0.0-nullsafety.1

* Require latest path_provider_windows to avoid potential issues
Expand Down
4 changes: 2 additions & 2 deletions packages/path_provider/path_provider/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: path_provider
description: Flutter plugin for getting commonly used locations on host platform file systems, such as the temp and app data directories.
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider
version: 2.0.0-nullsafety.1
version: 2.0.0-nullsafety.2

flutter:
plugin:
Expand All @@ -21,7 +21,7 @@ flutter:
dependencies:
flutter:
sdk: flutter
path_provider_platform_interface: ^2.0.0-nullsafety
path_provider_platform_interface: ^2.0.0-nullsafety.1
path_provider_macos: ^0.0.5-nullsafety
path_provider_linux: ^0.2.0-nullsafety
path_provider_windows: ^0.1.0-nullsafety.3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.0-nullsafety.1

* Removed pre-screening for platform.
* Updated tests accordingly.

## 2.0.0-nullsafety

* Migrate to null safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'enums.dart';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
import 'package:platform/platform.dart';

/// An implementation of [PathProviderPlatform] that uses method channels.
class MethodChannelPathProvider extends PathProviderPlatform {
Expand All @@ -18,18 +17,6 @@ class MethodChannelPathProvider extends PathProviderPlatform {
MethodChannel methodChannel =
MethodChannel('plugins.flutter.io/path_provider');

// Ideally, this property shouldn't exist, and each platform should
// just implement the supported methods. Once all the platforms are
// federated, this property should be removed.
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;
}

Future<String?> getTemporaryPath() {
return methodChannel.invokeMethod<String>('getTemporaryDirectory');
}
Expand All @@ -39,9 +26,6 @@ class MethodChannelPathProvider extends PathProviderPlatform {
}

Future<String?> getLibraryPath() {
if (!_platform.isIOS && !_platform.isMacOS) {
throw UnsupportedError('Functionality only available on iOS/macOS');
}
return methodChannel.invokeMethod<String>('getLibraryDirectory');
}

Expand All @@ -51,36 +35,24 @@ class MethodChannelPathProvider extends PathProviderPlatform {
}

Future<String?> getExternalStoragePath() {
if (!_platform.isAndroid) {
throw UnsupportedError('Functionality only available on Android');
}
return methodChannel.invokeMethod<String>('getStorageDirectory');
}

Future<List<String>?> getExternalCachePaths() {
if (!_platform.isAndroid) {
throw UnsupportedError('Functionality only available on Android');
}
return methodChannel
.invokeListMethod<String>('getExternalCacheDirectories');
}

Future<List<String>?> getExternalStoragePaths({
StorageDirectory? type,
}) async {
if (!_platform.isAndroid) {
throw UnsupportedError('Functionality only available on Android');
}
return methodChannel.invokeListMethod<String>(
'getExternalStorageDirectories',
<String, dynamic>{'type': type?.index},
);
}

Future<String?> getDownloadsPath() {
if (!_platform.isMacOS) {
throw UnsupportedError('Functionality only available on macOS');
}
return methodChannel.invokeMethod<String>('getDownloadsDirectory');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A common platform interface for the path_provider plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.0.0-nullsafety
version: 2.0.0-nullsafety.1

dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path_provider_platform_interface/src/enums.dart';
import 'package:path_provider_platform_interface/src/method_channel_path_provider.dart';
import 'package:platform/platform.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -49,10 +48,7 @@ void main() {
});
});

setUp(() {
methodChannelPathProvider.setMockPathProviderPlatform(
FakePlatform(operatingSystem: 'android'));
});
setUp(() {});

tearDown(() {
log.clear();
Expand All @@ -79,31 +75,7 @@ void main() {
expect(path, kApplicationSupportPath);
});

test('getLibraryPath android fails', () async {
try {
await methodChannelPathProvider.getLibraryPath();
fail('should throw UnsupportedError');
} catch (e) {
expect(e, isUnsupportedError);
}
});

test('getLibraryPath iOS succeeds', () async {
methodChannelPathProvider
.setMockPathProviderPlatform(FakePlatform(operatingSystem: 'ios'));

final String? path = await methodChannelPathProvider.getLibraryPath();
expect(
log,
<Matcher>[isMethodCall('getLibraryDirectory', arguments: null)],
);
expect(path, kLibraryPath);
});

test('getLibraryPath macOS succeeds', () async {
methodChannelPathProvider
.setMockPathProviderPlatform(FakePlatform(operatingSystem: 'macos'));

test('getLibraryPath', () async {
final String? path = await methodChannelPathProvider.getLibraryPath();
expect(
log,
Expand All @@ -124,7 +96,7 @@ void main() {
expect(path, kApplicationDocumentsPath);
});

test('getExternalCachePaths android succeeds', () async {
test('getExternalCachePaths', () async {
final List<String>? result =
await methodChannelPathProvider.getExternalCachePaths();
expect(
Expand All @@ -135,23 +107,11 @@ void main() {
expect(result.first, kExternalCachePaths);
});

test('getExternalCachePaths non-android fails', () async {
methodChannelPathProvider
.setMockPathProviderPlatform(FakePlatform(operatingSystem: 'ios'));

try {
await methodChannelPathProvider.getExternalCachePaths();
fail('should throw UnsupportedError');
} catch (e) {
expect(e, isUnsupportedError);
}
});

for (StorageDirectory? type in <StorageDirectory?>[
null,
...StorageDirectory.values
]) {
test('getExternalStoragePaths (type: $type) android succeeds', () async {
test('getExternalStoragePaths (type: $type)', () async {
final List<String>? result =
await methodChannelPathProvider.getExternalStoragePaths(type: type);
expect(
Expand All @@ -167,40 +127,15 @@ void main() {
expect(result!.length, 1);
expect(result.first, kExternalStoragePaths);
});

test('getExternalStoragePaths (type: $type) non-android fails', () async {
methodChannelPathProvider
.setMockPathProviderPlatform(FakePlatform(operatingSystem: 'ios'));

try {
await methodChannelPathProvider.getExternalStoragePaths();
fail('should throw UnsupportedError');
} catch (e) {
expect(e, isUnsupportedError);
}
});
} // end of for-loop

test('getDownloadsPath macos succeeds', () async {
methodChannelPathProvider
.setMockPathProviderPlatform(FakePlatform(operatingSystem: 'macos'));
test('getDownloadsPath', () async {
final String? result = await methodChannelPathProvider.getDownloadsPath();
expect(
log,
<Matcher>[isMethodCall('getDownloadsDirectory', arguments: null)],
);
expect(result, kDownloadsPath);
});

test('getDownloadsPath non-macos fails', () async {
methodChannelPathProvider.setMockPathProviderPlatform(
FakePlatform(operatingSystem: 'android'));
try {
await methodChannelPathProvider.getDownloadsPath();
fail('should throw UnsupportedError');
} catch (e) {
expect(e, isUnsupportedError);
}
});
});
}