From 9ccbfd70d35643f52c77387813665b56d6aeef5c Mon Sep 17 00:00:00 2001 From: Thomas Verbeek Date: Fri, 11 Sep 2020 10:13:40 +0200 Subject: [PATCH 1/3] PATH_PRVIDER: removed pre-screening for platform when calling getDownloadsPath --- packages/path_provider/path_provider/CHANGELOG.md | 4 ++++ packages/path_provider/path_provider/pubspec.yaml | 2 +- .../lib/src/method_channel_path_provider.dart | 3 --- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/path_provider/path_provider/CHANGELOG.md b/packages/path_provider/path_provider/CHANGELOG.md index 07778d5ccef3..0daac22c1456 100644 --- a/packages/path_provider/path_provider/CHANGELOG.md +++ b/packages/path_provider/path_provider/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.6.15 + +* Removed pre-screening for platform when calling getDownloadsPath + ## 1.6.14 * Update package:e2e -> package:integration_test diff --git a/packages/path_provider/path_provider/pubspec.yaml b/packages/path_provider/path_provider/pubspec.yaml index 7781c76331d4..46bdb7716f55 100644 --- a/packages/path_provider/path_provider/pubspec.yaml +++ b/packages/path_provider/path_provider/pubspec.yaml @@ -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.14 +version: 1.6.15 flutter: plugin: diff --git a/packages/path_provider/path_provider_platform_interface/lib/src/method_channel_path_provider.dart b/packages/path_provider/path_provider_platform_interface/lib/src/method_channel_path_provider.dart index 7826fa4365be..7329bc259c3e 100644 --- a/packages/path_provider/path_provider_platform_interface/lib/src/method_channel_path_provider.dart +++ b/packages/path_provider/path_provider_platform_interface/lib/src/method_channel_path_provider.dart @@ -78,9 +78,6 @@ class MethodChannelPathProvider extends PathProviderPlatform { } Future getDownloadsPath() { - if (!_platform.isMacOS) { - throw UnsupportedError('Functionality only available on macOS'); - } return methodChannel.invokeMethod('getDownloadsDirectory'); } } From b22dae1bf3650f47d9fd7648e778248d373705f9 Mon Sep 17 00:00:00 2001 From: Thomas Verbeek Date: Tue, 9 Feb 2021 12:24:50 +0100 Subject: [PATCH 2/3] removed pre-screening on all methods of method_channel_path_provider.dart also fixed/reduced tests to conform to this --- .../lib/src/method_channel_path_provider.dart | 27 +------ .../method_channel_path_provider_test.dart | 75 ++----------------- 2 files changed, 6 insertions(+), 96 deletions(-) diff --git a/packages/path_provider/path_provider_platform_interface/lib/src/method_channel_path_provider.dart b/packages/path_provider/path_provider_platform_interface/lib/src/method_channel_path_provider.dart index 1bc76a9be06f..11854b156605 100644 --- a/packages/path_provider/path_provider_platform_interface/lib/src/method_channel_path_provider.dart +++ b/packages/path_provider/path_provider_platform_interface/lib/src/method_channel_path_provider.dart @@ -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 { @@ -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 getTemporaryPath() { return methodChannel.invokeMethod('getTemporaryDirectory'); } @@ -39,9 +26,6 @@ class MethodChannelPathProvider extends PathProviderPlatform { } Future getLibraryPath() { - if (!_platform.isIOS && !_platform.isMacOS) { - throw UnsupportedError('Functionality only available on iOS/macOS'); - } return methodChannel.invokeMethod('getLibraryDirectory'); } @@ -51,16 +35,10 @@ class MethodChannelPathProvider extends PathProviderPlatform { } Future getExternalStoragePath() { - if (!_platform.isAndroid) { - throw UnsupportedError('Functionality only available on Android'); - } return methodChannel.invokeMethod('getStorageDirectory'); } Future?> getExternalCachePaths() { - if (!_platform.isAndroid) { - throw UnsupportedError('Functionality only available on Android'); - } return methodChannel .invokeListMethod('getExternalCacheDirectories'); } @@ -68,16 +46,13 @@ class MethodChannelPathProvider extends PathProviderPlatform { Future?> getExternalStoragePaths({ StorageDirectory? type, }) async { - if (!_platform.isAndroid) { - throw UnsupportedError('Functionality only available on Android'); - } return methodChannel.invokeListMethod( 'getExternalStorageDirectories', {'type': type?.index}, ); } - Future getDownloadsPath() { + Future getDownloadsPath() { return methodChannel.invokeMethod('getDownloadsDirectory'); } } diff --git a/packages/path_provider/path_provider_platform_interface/test/method_channel_path_provider_test.dart b/packages/path_provider/path_provider_platform_interface/test/method_channel_path_provider_test.dart index 7130d7743e69..eb2c7e64c0c7 100644 --- a/packages/path_provider/path_provider_platform_interface/test/method_channel_path_provider_test.dart +++ b/packages/path_provider/path_provider_platform_interface/test/method_channel_path_provider_test.dart @@ -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(); @@ -49,10 +48,7 @@ void main() { }); }); - setUp(() { - methodChannelPathProvider.setMockPathProviderPlatform( - FakePlatform(operatingSystem: 'android')); - }); + setUp(() {}); tearDown(() { log.clear(); @@ -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, - [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, @@ -124,7 +96,7 @@ void main() { expect(path, kApplicationDocumentsPath); }); - test('getExternalCachePaths android succeeds', () async { + test('getExternalCachePaths', () async { final List? result = await methodChannelPathProvider.getExternalCachePaths(); expect( @@ -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 [ null, ...StorageDirectory.values ]) { - test('getExternalStoragePaths (type: $type) android succeeds', () async { + test('getExternalStoragePaths (type: $type)', () async { final List? result = await methodChannelPathProvider.getExternalStoragePaths(type: type); expect( @@ -167,23 +127,9 @@ 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, @@ -191,16 +137,5 @@ void main() { ); 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); - } - }); }); } From ac8f3cad3acf6046d09bb91cb3909aa5c4a9db40 Mon Sep 17 00:00:00 2001 From: Thomas Verbeek Date: Wed, 10 Feb 2021 09:38:55 +0100 Subject: [PATCH 3/3] updated version and changelog message --- packages/path_provider/path_provider/CHANGELOG.md | 5 +++-- packages/path_provider/path_provider/pubspec.yaml | 2 +- .../path_provider_platform_interface/CHANGELOG.md | 5 +++++ .../path_provider_platform_interface/pubspec.yaml | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/path_provider/path_provider/CHANGELOG.md b/packages/path_provider/path_provider/CHANGELOG.md index 54e52a720d57..f6f306300199 100644 --- a/packages/path_provider/path_provider/CHANGELOG.md +++ b/packages/path_provider/path_provider/CHANGELOG.md @@ -1,6 +1,7 @@ -## 2.0.1-nullsafety +## 2.0.0-nullsafety.1 -* Removed pre-screening for platform when calling getDownloadsPath +* Removed pre-screening for platform. +* Updated tests accordingly. ## 2.0.0-nullsafety diff --git a/packages/path_provider/path_provider/pubspec.yaml b/packages/path_provider/path_provider/pubspec.yaml index cf9d14da26a7..fa7229de9390 100644 --- a/packages/path_provider/path_provider/pubspec.yaml +++ b/packages/path_provider/path_provider/pubspec.yaml @@ -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.1-nullsafety +version: 2.0.0-nullsafety.1 flutter: plugin: diff --git a/packages/path_provider/path_provider_platform_interface/CHANGELOG.md b/packages/path_provider/path_provider_platform_interface/CHANGELOG.md index 97121268c790..7d0a45934da4 100644 --- a/packages/path_provider/path_provider_platform_interface/CHANGELOG.md +++ b/packages/path_provider/path_provider_platform_interface/CHANGELOG.md @@ -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. diff --git a/packages/path_provider/path_provider_platform_interface/pubspec.yaml b/packages/path_provider/path_provider_platform_interface/pubspec.yaml index 946d2ed4b4fd..0de7ab82d321 100644 --- a/packages/path_provider/path_provider_platform_interface/pubspec.yaml +++ b/packages/path_provider/path_provider_platform_interface/pubspec.yaml @@ -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: