diff --git a/packages/path_provider/analysis_options.yaml b/packages/path_provider/analysis_options.yaml deleted file mode 100644 index cda4f6e153e6..000000000000 --- a/packages/path_provider/analysis_options.yaml +++ /dev/null @@ -1 +0,0 @@ -include: ../../analysis_options_legacy.yaml diff --git a/packages/path_provider/path_provider/example/integration_test/path_provider_test.dart b/packages/path_provider/path_provider/example/integration_test/path_provider_test.dart index 2613b45a8574..f1e7c0aef59b 100644 --- a/packages/path_provider/path_provider/example/integration_test/path_provider_test.dart +++ b/packages/path_provider/path_provider/example/integration_test/path_provider_test.dart @@ -4,8 +4,6 @@ // @dart=2.9 -import 'dart:async'; - import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; import 'package:path_provider/path_provider.dart'; @@ -55,7 +53,7 @@ void main() { expect(result, throwsA(isInstanceOf())); } else if (Platform.isAndroid) { final List directories = await getExternalCacheDirectories(); - for (Directory result in directories) { + for (final Directory result in directories) { _verifySampleFile(result, 'externalCache'); } } @@ -72,7 +70,7 @@ void main() { StorageDirectory.movies, ]; - for (StorageDirectory type in _allDirs) { + for (final StorageDirectory type in _allDirs) { test('getExternalStorageDirectories (type: $type)', () async { if (Platform.isIOS) { final Future> result = @@ -81,7 +79,7 @@ void main() { } else if (Platform.isAndroid) { final List directories = await getExternalStorageDirectories(type: type); - for (Directory result in directories) { + for (final Directory result in directories) { _verifySampleFile(result, '$type'); } } diff --git a/packages/path_provider/path_provider/example/lib/main.dart b/packages/path_provider/path_provider/example/lib/main.dart index 7b1d6a73a2f5..c0ac126b2a00 100644 --- a/packages/path_provider/path_provider/example/lib/main.dart +++ b/packages/path_provider/path_provider/example/lib/main.dart @@ -4,7 +4,6 @@ // ignore_for_file: public_member_api_docs -import 'dart:async'; import 'dart:io'; import 'package:flutter/material.dart'; @@ -22,13 +21,13 @@ class MyApp extends StatelessWidget { theme: ThemeData( primarySwatch: Colors.blue, ), - home: MyHomePage(title: 'Path Provider'), + home: const MyHomePage(title: 'Path Provider'), ); } } class MyHomePage extends StatefulWidget { - MyHomePage({Key? key, required this.title}) : super(key: key); + const MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @override @@ -166,8 +165,9 @@ class _MyHomePageState extends State { Padding( padding: const EdgeInsets.all(16.0), child: ElevatedButton( - child: Text( - '${Platform.isIOS ? "External directories are unavailable " "on iOS" : "Get External Storage Directory"}'), + child: Text(Platform.isIOS + ? 'External directories are unavailable on iOS' + : 'Get External Storage Directory'), onPressed: Platform.isIOS ? null : _requestExternalStorageDirectory, ), @@ -178,8 +178,9 @@ class _MyHomePageState extends State { Padding( padding: const EdgeInsets.all(16.0), child: ElevatedButton( - child: Text( - '${Platform.isIOS ? "External directories are unavailable " "on iOS" : "Get External Storage Directories"}'), + child: Text(Platform.isIOS + ? 'External directories are unavailable on iOS' + : 'Get External Storage Directories'), onPressed: Platform.isIOS ? null : () { @@ -197,8 +198,9 @@ class _MyHomePageState extends State { Padding( padding: const EdgeInsets.all(16.0), child: ElevatedButton( - child: Text( - '${Platform.isIOS ? "External directories are unavailable " "on iOS" : "Get External Cache Directories"}'), + child: Text(Platform.isIOS + ? 'External directories are unavailable on iOS' + : 'Get External Cache Directories'), onPressed: Platform.isIOS ? null : _requestExternalCacheDirectories, ), diff --git a/packages/path_provider/path_provider/example/test_driver/integration_test.dart b/packages/path_provider/path_provider/example/test_driver/integration_test.dart index 18ed3cff3ee8..24a0ee720b2a 100644 --- a/packages/path_provider/path_provider/example/test_driver/integration_test.dart +++ b/packages/path_provider/path_provider/example/test_driver/integration_test.dart @@ -4,7 +4,6 @@ // @dart=2.9 -import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'package:flutter_driver/flutter_driver.dart'; @@ -14,6 +13,6 @@ Future main() async { final String data = await driver.requestData(null, timeout: const Duration(minutes: 1)); await driver.close(); - final Map result = jsonDecode(data); + final Map result = jsonDecode(data) as Map; exit(result['result'] == 'true' ? 0 : 1); } diff --git a/packages/path_provider/path_provider/lib/path_provider.dart b/packages/path_provider/path_provider/lib/path_provider.dart index d63887a60267..a51aefe8e29f 100644 --- a/packages/path_provider/path_provider/lib/path_provider.dart +++ b/packages/path_provider/path_provider/lib/path_provider.dart @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:async'; import 'dart:io' show Directory, Platform; import 'package:flutter/foundation.dart' show kIsWeb, visibleForTesting; import 'package:path_provider_linux/path_provider_linux.dart'; import 'package:path_provider_windows/path_provider_windows.dart'; import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; +// ignore: implementation_imports import 'package:path_provider_platform_interface/src/method_channel_path_provider.dart'; export 'package:path_provider_platform_interface/path_provider_platform_interface.dart' @@ -36,7 +36,7 @@ class MissingPlatformDirectoryException implements Exception { @override String toString() { - String detailsAddition = details == null ? '' : ': $details'; + final String detailsAddition = details == null ? '' : ': $details'; return 'MissingPlatformDirectoryException($message)$detailsAddition'; } } diff --git a/packages/path_provider/path_provider/test/path_provider_test.dart b/packages/path_provider/path_provider/test/path_provider_test.dart index 7232a74a1253..218861606209 100644 --- a/packages/path_provider/path_provider/test/path_provider_test.dart +++ b/packages/path_provider/path_provider/test/path_provider_test.dart @@ -3,7 +3,6 @@ // found in the LICENSE file. import 'dart:io' show Directory; -import 'dart:async'; import 'package:flutter_test/flutter_test.dart'; import 'package:path_provider/path_provider.dart'; @@ -27,44 +26,44 @@ void main() { }); test('getTemporaryDirectory', () async { - Directory result = await getTemporaryDirectory(); + final Directory result = await getTemporaryDirectory(); expect(result.path, kTemporaryPath); }); test('getApplicationSupportDirectory', () async { - Directory result = await getApplicationSupportDirectory(); + final Directory result = await getApplicationSupportDirectory(); expect(result.path, kApplicationSupportPath); }); test('getLibraryDirectory', () async { - Directory result = await getLibraryDirectory(); + final Directory result = await getLibraryDirectory(); expect(result.path, kLibraryPath); }); test('getApplicationDocumentsDirectory', () async { - Directory result = await getApplicationDocumentsDirectory(); + final Directory result = await getApplicationDocumentsDirectory(); expect(result.path, kApplicationDocumentsPath); }); test('getExternalStorageDirectory', () async { - Directory? result = await getExternalStorageDirectory(); + final Directory? result = await getExternalStorageDirectory(); expect(result?.path, kExternalStoragePath); }); test('getExternalCacheDirectories', () async { - List? result = await getExternalCacheDirectories(); + final List? result = await getExternalCacheDirectories(); expect(result?.length, 1); expect(result?.first.path, kExternalCachePath); }); test('getExternalStorageDirectories', () async { - List? result = await getExternalStorageDirectories(); + final List? result = await getExternalStorageDirectories(); expect(result?.length, 1); expect(result?.first.path, kExternalStoragePath); }); test('getDownloadsDirectory', () async { - Directory? result = await getDownloadsDirectory(); + final Directory? result = await getDownloadsDirectory(); expect(result?.path, kDownloadsPath); }); }); @@ -95,22 +94,22 @@ void main() { }); test('getExternalStorageDirectory passes null through', () async { - Directory? result = await getExternalStorageDirectory(); + final Directory? result = await getExternalStorageDirectory(); expect(result, isNull); }); test('getExternalCacheDirectories passes null through', () async { - List? result = await getExternalCacheDirectories(); + final List? result = await getExternalCacheDirectories(); expect(result, isNull); }); test('getExternalStorageDirectories passes null through', () async { - List? result = await getExternalStorageDirectories(); + final List? result = await getExternalStorageDirectories(); expect(result, isNull); }); test('getDownloadsDirectory passses null through', () async { - Directory? result = await getDownloadsDirectory(); + final Directory? result = await getDownloadsDirectory(); expect(result, isNull); }); }); @@ -119,36 +118,44 @@ void main() { class FakePathProviderPlatform extends Fake with MockPlatformInterfaceMixin implements PathProviderPlatform { + @override Future getTemporaryPath() async { return kTemporaryPath; } + @override Future getApplicationSupportPath() async { return kApplicationSupportPath; } + @override Future getLibraryPath() async { return kLibraryPath; } + @override Future getApplicationDocumentsPath() async { return kApplicationDocumentsPath; } + @override Future getExternalStoragePath() async { return kExternalStoragePath; } + @override Future?> getExternalCachePaths() async { return [kExternalCachePath]; } + @override Future?> getExternalStoragePaths({ StorageDirectory? type, }) async { return [kExternalStoragePath]; } + @override Future getDownloadsPath() async { return kDownloadsPath; } @@ -157,36 +164,44 @@ class FakePathProviderPlatform extends Fake class AllNullFakePathProviderPlatform extends Fake with MockPlatformInterfaceMixin implements PathProviderPlatform { + @override Future getTemporaryPath() async { return null; } + @override Future getApplicationSupportPath() async { return null; } + @override Future getLibraryPath() async { return null; } + @override Future getApplicationDocumentsPath() async { return null; } + @override Future getExternalStoragePath() async { return null; } + @override Future?> getExternalCachePaths() async { return null; } + @override Future?> getExternalStoragePaths({ StorageDirectory? type, }) async { return null; } + @override Future getDownloadsPath() async { return null; } diff --git a/packages/path_provider/path_provider_linux/example/lib/main.dart b/packages/path_provider/path_provider_linux/example/lib/main.dart index 104c998bc61a..d365e6bdeab4 100644 --- a/packages/path_provider/path_provider_linux/example/lib/main.dart +++ b/packages/path_provider/path_provider_linux/example/lib/main.dart @@ -3,8 +3,6 @@ // found in the LICENSE file. import 'package:flutter/material.dart'; -import 'dart:async'; - import 'package:flutter/services.dart'; import 'package:path_provider_linux/path_provider_linux.dart'; @@ -67,7 +65,9 @@ class _MyAppState extends State { // If the widget was removed from the tree while the asynchronous platform // message was in flight, we want to discard the reply rather than calling // setState to update our non-existent appearance. - if (!mounted) return; + if (!mounted) { + return; + } setState(() { _tempDirectory = tempDirectory; @@ -86,7 +86,7 @@ class _MyAppState extends State { ), body: Center( child: Column( - children: [ + children: [ Text('Temp Directory: $_tempDirectory\n'), Text('Documents Directory: $_documentsDirectory\n'), Text('Downloads Directory: $_downloadsDirectory\n'), diff --git a/packages/path_provider/path_provider_linux/example/test/widget_test.dart b/packages/path_provider/path_provider_linux/example/test/widget_test.dart index 4d5da3e4e330..59f839d431fa 100644 --- a/packages/path_provider/path_provider_linux/example/test/widget_test.dart +++ b/packages/path_provider/path_provider_linux/example/test/widget_test.dart @@ -9,8 +9,6 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. -import 'dart:async'; - import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -19,14 +17,14 @@ import 'package:pathproviderexample/main.dart'; void main() { group('Test linux path provider example', () { setUpAll(() async { - await WidgetsFlutterBinding.ensureInitialized(); + WidgetsFlutterBinding.ensureInitialized(); }); testWidgets('Finds tmp directory', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.runAsync(() async { await tester.pumpWidget(MyApp()); - await Future.delayed(Duration(milliseconds: 20)); + await Future.delayed(const Duration(milliseconds: 20)); await tester.pump(); // Verify that temporary directory is retrieved. @@ -44,7 +42,7 @@ void main() { // Build our app and trigger a frame. await tester.runAsync(() async { await tester.pumpWidget(MyApp()); - await Future.delayed(Duration(milliseconds: 20)); + await Future.delayed(const Duration(milliseconds: 20)); await tester.pump(); // Verify that documents directory is retrieved. @@ -62,7 +60,7 @@ void main() { // Build our app and trigger a frame. await tester.runAsync(() async { await tester.pumpWidget(MyApp()); - await Future.delayed(Duration(milliseconds: 20)); + await Future.delayed(const Duration(milliseconds: 20)); await tester.pump(); // Verify that downloads directory is retrieved. @@ -81,7 +79,7 @@ void main() { // Build our app and trigger a frame. await tester.runAsync(() async { await tester.pumpWidget(MyApp()); - await Future.delayed(Duration(milliseconds: 20)); + await Future.delayed(const Duration(milliseconds: 20)); await tester.pump(); // Verify that Application Support Directory is retrieved. diff --git a/packages/path_provider/path_provider_linux/example/test_driver/integration_test.dart b/packages/path_provider/path_provider_linux/example/test_driver/integration_test.dart index 18ed3cff3ee8..24a0ee720b2a 100644 --- a/packages/path_provider/path_provider_linux/example/test_driver/integration_test.dart +++ b/packages/path_provider/path_provider_linux/example/test_driver/integration_test.dart @@ -4,7 +4,6 @@ // @dart=2.9 -import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'package:flutter_driver/flutter_driver.dart'; @@ -14,6 +13,6 @@ Future main() async { final String data = await driver.requestData(null, timeout: const Duration(minutes: 1)); await driver.close(); - final Map result = jsonDecode(data); + final Map result = jsonDecode(data) as Map; exit(result['result'] == 'true' ? 0 : 1); } diff --git a/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart b/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart index cf8d12436429..5a81114cc92d 100644 --- a/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart +++ b/packages/path_provider/path_provider_linux/lib/path_provider_linux.dart @@ -1,12 +1,12 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. + import 'dart:io'; -import 'dart:async'; -import 'package:xdg_directories/xdg_directories.dart' as xdg; import 'package:path/path.dart' as path; import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; +import 'package:xdg_directories/xdg_directories.dart' as xdg; /// The linux implementation of [PathProviderPlatform] /// @@ -19,16 +19,17 @@ class PathProviderLinux extends PathProviderPlatform { @override Future getTemporaryPath() { - return Future.value("/tmp"); + return Future.value('/tmp'); } @override Future getApplicationSupportPath() async { - final processName = path.basenameWithoutExtension( + final String processName = path.basenameWithoutExtension( await File('/proc/self/exe').resolveSymbolicLinks()); - final directory = Directory(path.join(xdg.dataHome.path, processName)); + final Directory directory = + Directory(path.join(xdg.dataHome.path, processName)); // Creating the directory if it doesn't exist, because mobile implementations assume the directory exists - if (!await directory.exists()) { + if (!directory.existsSync()) { await directory.create(recursive: true); } return directory.path; @@ -36,11 +37,11 @@ class PathProviderLinux extends PathProviderPlatform { @override Future getApplicationDocumentsPath() { - return Future.value(xdg.getUserDirectory('DOCUMENTS')?.path); + return Future.value(xdg.getUserDirectory('DOCUMENTS')?.path); } @override Future getDownloadsPath() { - return Future.value(xdg.getUserDirectory('DOWNLOAD')?.path); + return Future.value(xdg.getUserDirectory('DOWNLOAD')?.path); } } diff --git a/packages/path_provider/path_provider_linux/test/path_provider_linux_test.dart b/packages/path_provider/path_provider_linux/test/path_provider_linux_test.dart index 81329fb7c3cb..9ab75ff477de 100644 --- a/packages/path_provider/path_provider_linux/test/path_provider_linux_test.dart +++ b/packages/path_provider/path_provider_linux/test/path_provider_linux_test.dart @@ -14,7 +14,7 @@ void main() { tearDown(() {}); test('getTemporaryPath', () async { - final plugin = PathProviderPlatform.instance; + final PathProviderPlatform plugin = PathProviderPlatform.instance; expect(await plugin.getTemporaryPath(), '/tmp'); }); } diff --git a/packages/path_provider/path_provider_macos/example/lib/main.dart b/packages/path_provider/path_provider_macos/example/lib/main.dart index 19ba86e31cf5..67a0eb32eeda 100644 --- a/packages/path_provider/path_provider_macos/example/lib/main.dart +++ b/packages/path_provider/path_provider_macos/example/lib/main.dart @@ -4,8 +4,6 @@ // ignore_for_file: public_member_api_docs -import 'dart:async'; - import 'package:flutter/material.dart'; import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; @@ -79,7 +77,7 @@ class _MyAppState extends State { ), body: Center( child: Column( - children: [ + children: [ Text('Temp Directory: $_tempDirectory\n'), Text('Documents Directory: $_documentsDirectory\n'), Text('Downloads Directory: $_downloadsDirectory\n'), diff --git a/packages/path_provider/path_provider_macos/example/test_driver/integration_test.dart b/packages/path_provider/path_provider_macos/example/test_driver/integration_test.dart index 18ed3cff3ee8..24a0ee720b2a 100644 --- a/packages/path_provider/path_provider_macos/example/test_driver/integration_test.dart +++ b/packages/path_provider/path_provider_macos/example/test_driver/integration_test.dart @@ -4,7 +4,6 @@ // @dart=2.9 -import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'package:flutter_driver/flutter_driver.dart'; @@ -14,6 +13,6 @@ Future main() async { final String data = await driver.requestData(null, timeout: const Duration(minutes: 1)); await driver.close(); - final Map result = jsonDecode(data); + final Map result = jsonDecode(data) as Map; exit(result['result'] == 'true' ? 0 : 1); } diff --git a/packages/path_provider/path_provider_platform_interface/lib/path_provider_platform_interface.dart b/packages/path_provider/path_provider_platform_interface/lib/path_provider_platform_interface.dart index 3eb1580711ef..99e600d05263 100644 --- a/packages/path_provider/path_provider_platform_interface/lib/path_provider_platform_interface.dart +++ b/packages/path_provider/path_provider_platform_interface/lib/path_provider_platform_interface.dart @@ -2,13 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:async'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'src/enums.dart'; import 'src/method_channel_path_provider.dart'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - export 'src/enums.dart'; /// The interface that implementations of path_provider must implement. 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 7889e004126f..007787444adb 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 @@ -2,21 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:async'; - -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'; +import 'enums.dart'; + /// An implementation of [PathProviderPlatform] that uses method channels. class MethodChannelPathProvider extends PathProviderPlatform { /// The method channel used to interact with the native platform. @visibleForTesting MethodChannel methodChannel = - MethodChannel('plugins.flutter.io/path_provider'); + const 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 @@ -30,14 +28,17 @@ class MethodChannelPathProvider extends PathProviderPlatform { _platform = platform; } + @override Future getTemporaryPath() { return methodChannel.invokeMethod('getTemporaryDirectory'); } + @override Future getApplicationSupportPath() { return methodChannel.invokeMethod('getApplicationSupportDirectory'); } + @override Future getLibraryPath() { if (!_platform.isIOS && !_platform.isMacOS) { throw UnsupportedError('Functionality only available on iOS/macOS'); @@ -45,11 +46,13 @@ class MethodChannelPathProvider extends PathProviderPlatform { return methodChannel.invokeMethod('getLibraryDirectory'); } + @override Future getApplicationDocumentsPath() { return methodChannel .invokeMethod('getApplicationDocumentsDirectory'); } + @override Future getExternalStoragePath() { if (!_platform.isAndroid) { throw UnsupportedError('Functionality only available on Android'); @@ -57,6 +60,7 @@ class MethodChannelPathProvider extends PathProviderPlatform { return methodChannel.invokeMethod('getStorageDirectory'); } + @override Future?> getExternalCachePaths() { if (!_platform.isAndroid) { throw UnsupportedError('Functionality only available on Android'); @@ -65,6 +69,7 @@ class MethodChannelPathProvider extends PathProviderPlatform { .invokeListMethod('getExternalCacheDirectories'); } + @override Future?> getExternalStoragePaths({ StorageDirectory? type, }) async { @@ -77,6 +82,7 @@ class MethodChannelPathProvider extends PathProviderPlatform { ); } + @override Future getDownloadsPath() { if (!_platform.isMacOS) { throw UnsupportedError('Functionality only available on macOS'); 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 71d55861c7b1..69c9b2b01f19 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 @@ -147,7 +147,7 @@ void main() { } }); - for (StorageDirectory? type in [ + for (final StorageDirectory? type in [ null, ...StorageDirectory.values ]) { diff --git a/packages/path_provider/path_provider_windows/example/lib/main.dart b/packages/path_provider/path_provider_windows/example/lib/main.dart index b4b0f999d937..509292bf7405 100644 --- a/packages/path_provider/path_provider_windows/example/lib/main.dart +++ b/packages/path_provider/path_provider_windows/example/lib/main.dart @@ -4,8 +4,6 @@ // ignore_for_file: public_member_api_docs -import 'dart:async'; - import 'package:flutter/material.dart'; import 'package:path_provider_windows/path_provider_windows.dart'; @@ -79,7 +77,7 @@ class _MyAppState extends State { ), body: Center( child: Column( - children: [ + children: [ Text('Temp Directory: $_tempDirectory\n'), Text('Documents Directory: $_documentsDirectory\n'), Text('Downloads Directory: $_downloadsDirectory\n'), diff --git a/packages/path_provider/path_provider_windows/example/test_driver/integration_test.dart b/packages/path_provider/path_provider_windows/example/test_driver/integration_test.dart index 18ed3cff3ee8..24a0ee720b2a 100644 --- a/packages/path_provider/path_provider_windows/example/test_driver/integration_test.dart +++ b/packages/path_provider/path_provider_windows/example/test_driver/integration_test.dart @@ -4,7 +4,6 @@ // @dart=2.9 -import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'package:flutter_driver/flutter_driver.dart'; @@ -14,6 +13,6 @@ Future main() async { final String data = await driver.requestData(null, timeout: const Duration(minutes: 1)); await driver.close(); - final Map result = jsonDecode(data); + final Map result = jsonDecode(data) as Map; exit(result['result'] == 'true' ? 0 : 1); } diff --git a/packages/path_provider/path_provider_windows/lib/src/folders.dart b/packages/path_provider/path_provider_windows/lib/src/folders.dart index e8112c1a953a..55def29df2d7 100644 --- a/packages/path_provider/path_provider_windows/lib/src/folders.dart +++ b/packages/path_provider/path_provider_windows/lib/src/folders.dart @@ -4,6 +4,9 @@ import 'package:win32/win32.dart'; +// ignore_for_file: non_constant_identifier_names + +// ignore: avoid_classes_with_only_static_members /// A class containing the GUID references for each of the documented Windows /// known folders. A property of this class may be passed to the `getPath` /// method in the [PathProvidersWindows] class to retrieve a known folder from diff --git a/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart b/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart index 5fef0dba32ed..13841a058638 100644 --- a/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart +++ b/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart @@ -2,9 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:async'; -import 'dart:io'; import 'dart:ffi'; +import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:meta/meta.dart'; @@ -22,14 +21,15 @@ import 'folders.dart'; class VersionInfoQuerier { /// Returns the value for [key] in [versionInfo]s English strings section, or /// null if there is no such entry, or if versionInfo is null. - getStringValue(Pointer? versionInfo, key) { + String? getStringValue(Pointer? versionInfo, String key) { if (versionInfo == null) { return null; } - const kEnUsLanguageCode = '040904e4'; - final keyPath = TEXT('\\StringFileInfo\\$kEnUsLanguageCode\\$key'); - final length = calloc(); - final valueAddress = calloc>(); + const String kEnUsLanguageCode = '040904e4'; + final Pointer keyPath = + TEXT('\\StringFileInfo\\$kEnUsLanguageCode\\$key'); + final Pointer length = calloc(); + final Pointer> valueAddress = calloc>(); try { if (VerQueryValue(versionInfo, keyPath, valueAddress, length) == 0) { return null; @@ -54,14 +54,14 @@ class PathProviderWindows extends PathProviderPlatform { /// This is typically the same as the TMP environment variable. @override Future getTemporaryPath() async { - final buffer = calloc(MAX_PATH + 1).cast(); + final Pointer buffer = calloc(MAX_PATH + 1).cast(); String path; try { - final length = GetTempPath(MAX_PATH, buffer); + final int length = GetTempPath(MAX_PATH, buffer); if (length == 0) { - final error = GetLastError(); + final int error = GetLastError(); throw WindowsException(error); } else { path = buffer.toDartString(); @@ -69,18 +69,18 @@ class PathProviderWindows extends PathProviderPlatform { // GetTempPath adds a trailing backslash, but SHGetKnownFolderPath does // not. Strip off trailing backslash for consistency with other methods // here. - if (path.endsWith('\\')) { + if (path.endsWith(r'\')) { path = path.substring(0, path.length - 1); } } // Ensure that the directory exists, since GetTempPath doesn't. - final directory = Directory(path); + final Directory directory = Directory(path); if (!directory.existsSync()) { await directory.create(recursive: true); } - return Future.value(path); + return path; } finally { calloc.free(buffer); } @@ -88,8 +88,8 @@ class PathProviderWindows extends PathProviderPlatform { @override Future getApplicationSupportPath() async { - final appDataRoot = await getPath(WindowsKnownFolder.RoamingAppData); - final directory = Directory( + final String appDataRoot = await getPath(WindowsKnownFolder.RoamingAppData); + final Directory directory = Directory( path.join(appDataRoot, _getApplicationSpecificSubdirectory())); // Ensure that the directory exists if possible, since it will on other // platforms. If the name is longer than MAXPATH, creating will fail, so @@ -115,11 +115,11 @@ class PathProviderWindows extends PathProviderPlatform { /// folderID is a GUID that represents a specific known folder ID, drawn from /// [WindowsKnownFolder]. Future getPath(String folderID) { - final pathPtrPtr = calloc>(); + final Pointer> pathPtrPtr = calloc>(); final Pointer knownFolderID = calloc()..ref.setGUID(folderID); try { - final hr = SHGetKnownFolderPath( + final int hr = SHGetKnownFolderPath( knownFolderID, KF_FLAG_DEFAULT, NULL, @@ -132,8 +132,8 @@ class PathProviderWindows extends PathProviderPlatform { } } - final path = pathPtrPtr.value.toDartString(); - return Future.value(path); + final String path = pathPtrPtr.value.toDartString(); + return Future.value(path); } finally { calloc.free(pathPtrPtr); calloc.free(knownFolderID); @@ -160,14 +160,15 @@ class PathProviderWindows extends PathProviderPlatform { Pointer? infoBuffer; try { // Get the module name. - final moduleNameLength = GetModuleFileName(0, moduleNameBuffer, MAX_PATH); + final int moduleNameLength = + GetModuleFileName(0, moduleNameBuffer, MAX_PATH); if (moduleNameLength == 0) { - final error = GetLastError(); + final int error = GetLastError(); throw WindowsException(error); } // From that, load the VERSIONINFO resource - int infoSize = GetFileVersionInfoSize(moduleNameBuffer, unused); + final int infoSize = GetFileVersionInfoSize(moduleNameBuffer, unused); if (infoSize != 0) { infoBuffer = calloc(infoSize); if (GetFileVersionInfo(moduleNameBuffer, 0, infoSize, infoBuffer) == @@ -182,10 +183,8 @@ class PathProviderWindows extends PathProviderPlatform { versionInfoQuerier.getStringValue(infoBuffer, 'ProductName')); // If there was no product name, use the executable name. - if (productName == null) { - productName = - path.basenameWithoutExtension(moduleNameBuffer.toDartString()); - } + productName ??= + path.basenameWithoutExtension(moduleNameBuffer.toDartString()); return companyName != null ? path.join(companyName, productName) @@ -214,7 +213,7 @@ class PathProviderWindows extends PathProviderPlatform { .trimRight() // Ensure that it does not end with a '.'. .replaceAll(RegExp(r'[.]+$'), ''); - const kMaxComponentLength = 255; + const int kMaxComponentLength = 255; if (sanitized.length > kMaxComponentLength) { sanitized = sanitized.substring(0, kMaxComponentLength); } diff --git a/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_stub.dart b/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_stub.dart index 69094af9eafa..91334d95ae24 100644 --- a/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_stub.dart +++ b/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_stub.dart @@ -14,9 +14,7 @@ import 'package:path_provider_platform_interface/path_provider_platform_interfac class PathProviderWindows extends PathProviderPlatform { /// Errors on attempted instantiation of the stub. It exists only to satisfy /// compile-time dependencies, and should never actually be created. - PathProviderWindows() { - assert(false); - } + PathProviderWindows() : assert(false); /// Stub; see comment on VersionInfoQuerier. VersionInfoQuerier versionInfoQuerier = VersionInfoQuerier(); diff --git a/packages/path_provider/path_provider_windows/test/path_provider_windows_test.dart b/packages/path_provider/path_provider_windows/test/path_provider_windows_test.dart index 22683d721e7c..a66c9e1ffb0d 100644 --- a/packages/path_provider/path_provider_windows/test/path_provider_windows_test.dart +++ b/packages/path_provider/path_provider_windows/test/path_provider_windows_test.dart @@ -13,20 +13,21 @@ class FakeVersionInfoQuerier implements VersionInfoQuerier { final Map responses; - getStringValue(Pointer? versionInfo, key) => responses[key]; + String? getStringValue(Pointer? versionInfo, String key) => + responses[key]; } void main() { test('getTemporaryPath', () async { - final pathProvider = PathProviderWindows(); + final PathProviderWindows pathProvider = PathProviderWindows(); expect(await pathProvider.getTemporaryPath(), contains(r'C:\')); }, skip: !Platform.isWindows); test('getApplicationSupportPath with no version info', () async { - final pathProvider = PathProviderWindows(); + final PathProviderWindows pathProvider = PathProviderWindows(); pathProvider.versionInfoQuerier = FakeVersionInfoQuerier({}); - final path = await pathProvider.getApplicationSupportPath(); + final String? path = await pathProvider.getApplicationSupportPath(); expect(path, contains(r'C:\')); expect(path, contains(r'AppData')); // The last path component should be the executable name. @@ -34,12 +35,12 @@ void main() { }, skip: !Platform.isWindows); test('getApplicationSupportPath with full version info', () async { - final pathProvider = PathProviderWindows(); + final PathProviderWindows pathProvider = PathProviderWindows(); pathProvider.versionInfoQuerier = FakeVersionInfoQuerier({ 'CompanyName': 'A Company', 'ProductName': 'Amazing App', }); - final path = await pathProvider.getApplicationSupportPath(); + final String? path = await pathProvider.getApplicationSupportPath(); expect(path, isNotNull); if (path != null) { expect(path, endsWith(r'AppData\Roaming\A Company\Amazing App')); @@ -48,11 +49,11 @@ void main() { }, skip: !Platform.isWindows); test('getApplicationSupportPath with missing company', () async { - final pathProvider = PathProviderWindows(); + final PathProviderWindows pathProvider = PathProviderWindows(); pathProvider.versionInfoQuerier = FakeVersionInfoQuerier({ 'ProductName': 'Amazing App', }); - final path = await pathProvider.getApplicationSupportPath(); + final String? path = await pathProvider.getApplicationSupportPath(); expect(path, isNotNull); if (path != null) { expect(path, endsWith(r'AppData\Roaming\Amazing App')); @@ -61,12 +62,12 @@ void main() { }, skip: !Platform.isWindows); test('getApplicationSupportPath with problematic values', () async { - final pathProvider = PathProviderWindows(); + final PathProviderWindows pathProvider = PathProviderWindows(); pathProvider.versionInfoQuerier = FakeVersionInfoQuerier({ 'CompanyName': r'A Company: Name.', 'ProductName': r'A"/Terrible\|App?*Name', }); - final path = await pathProvider.getApplicationSupportPath(); + final String? path = await pathProvider.getApplicationSupportPath(); expect(path, isNotNull); if (path != null) { expect( @@ -79,12 +80,12 @@ void main() { }, skip: !Platform.isWindows); test('getApplicationSupportPath with a completely invalid company', () async { - final pathProvider = PathProviderWindows(); + final PathProviderWindows pathProvider = PathProviderWindows(); pathProvider.versionInfoQuerier = FakeVersionInfoQuerier({ 'CompanyName': r'..', 'ProductName': r'Amazing App', }); - final path = await pathProvider.getApplicationSupportPath(); + final String? path = await pathProvider.getApplicationSupportPath(); expect(path, isNotNull); if (path != null) { expect(path, endsWith(r'AppData\Roaming\Amazing App')); @@ -93,28 +94,28 @@ void main() { }, skip: !Platform.isWindows); test('getApplicationSupportPath with very long app name', () async { - final pathProvider = PathProviderWindows(); - final truncatedName = 'A' * 255; + final PathProviderWindows pathProvider = PathProviderWindows(); + final String truncatedName = 'A' * 255; pathProvider.versionInfoQuerier = FakeVersionInfoQuerier({ 'CompanyName': 'A Company', 'ProductName': truncatedName * 2, }); - final path = await pathProvider.getApplicationSupportPath(); + final String? path = await pathProvider.getApplicationSupportPath(); expect(path, endsWith('\\$truncatedName')); // The directory won't exist, since it's longer than MAXPATH, so don't check // that here. }, skip: !Platform.isWindows); test('getApplicationDocumentsPath', () async { - final pathProvider = PathProviderWindows(); - final path = await pathProvider.getApplicationDocumentsPath(); + final PathProviderWindows pathProvider = PathProviderWindows(); + final String? path = await pathProvider.getApplicationDocumentsPath(); expect(path, contains(r'C:\')); expect(path, contains(r'Documents')); }, skip: !Platform.isWindows); test('getDownloadsPath', () async { - final pathProvider = PathProviderWindows(); - final path = await pathProvider.getDownloadsPath(); + final PathProviderWindows pathProvider = PathProviderWindows(); + final String? path = await pathProvider.getDownloadsPath(); expect(path, contains(r'C:\')); expect(path, contains(r'Downloads')); }, skip: !Platform.isWindows); diff --git a/script/incremental_build.sh b/script/incremental_build.sh index ade89afe4ca1..f0c4bc4ac35e 100755 --- a/script/incremental_build.sh +++ b/script/incremental_build.sh @@ -42,7 +42,6 @@ CUSTOM_ANALYSIS_PLUGINS=( ios_platform_images local_auth package_info - path_provider plugin_platform_interface quick_actions sensors