Skip to content

Commit

Permalink
[path_provider] Switch to new analysis options (flutter#3755)
Browse files Browse the repository at this point in the history
Removes the override to use the legacy analysis, and fixes all resulting issues.

Part of flutter/flutter#76229
  • Loading branch information
stuartmorgan authored Mar 31, 2021
1 parent 0db60bb commit febc3e3
Show file tree
Hide file tree
Showing 23 changed files with 132 additions and 123 deletions.
1 change: 0 additions & 1 deletion packages/path_provider/analysis_options.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -55,7 +53,7 @@ void main() {
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
} else if (Platform.isAndroid) {
final List<Directory> directories = await getExternalCacheDirectories();
for (Directory result in directories) {
for (final Directory result in directories) {
_verifySampleFile(result, 'externalCache');
}
}
Expand All @@ -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<List<Directory>> result =
Expand All @@ -81,7 +79,7 @@ void main() {
} else if (Platform.isAndroid) {
final List<Directory> directories =
await getExternalStorageDirectories(type: type);
for (Directory result in directories) {
for (final Directory result in directories) {
_verifySampleFile(result, '$type');
}
}
Expand Down
20 changes: 11 additions & 9 deletions packages/path_provider/path_provider/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

// ignore_for_file: public_member_api_docs

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
Expand All @@ -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
Expand Down Expand Up @@ -166,8 +165,9 @@ class _MyHomePageState extends State<MyHomePage> {
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,
),
Expand All @@ -178,8 +178,9 @@ class _MyHomePageState extends State<MyHomePage> {
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
: () {
Expand All @@ -197,8 +198,9 @@ class _MyHomePageState extends State<MyHomePage> {
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,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

// @dart=2.9

import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter_driver/flutter_driver.dart';
Expand All @@ -14,6 +13,6 @@ Future<void> main() async {
final String data =
await driver.requestData(null, timeout: const Duration(minutes: 1));
await driver.close();
final Map<String, dynamic> result = jsonDecode(data);
final Map<String, dynamic> result = jsonDecode(data) as Map<String, dynamic>;
exit(result['result'] == 'true' ? 0 : 1);
}
4 changes: 2 additions & 2 deletions packages/path_provider/path_provider/lib/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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';
}
}
Expand Down
41 changes: 28 additions & 13 deletions packages/path_provider/path_provider/test/path_provider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<Directory>? result = await getExternalCacheDirectories();
final List<Directory>? result = await getExternalCacheDirectories();
expect(result?.length, 1);
expect(result?.first.path, kExternalCachePath);
});

test('getExternalStorageDirectories', () async {
List<Directory>? result = await getExternalStorageDirectories();
final List<Directory>? 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);
});
});
Expand Down Expand Up @@ -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<Directory>? result = await getExternalCacheDirectories();
final List<Directory>? result = await getExternalCacheDirectories();
expect(result, isNull);
});

test('getExternalStorageDirectories passes null through', () async {
List<Directory>? result = await getExternalStorageDirectories();
final List<Directory>? result = await getExternalStorageDirectories();
expect(result, isNull);
});

test('getDownloadsDirectory passses null through', () async {
Directory? result = await getDownloadsDirectory();
final Directory? result = await getDownloadsDirectory();
expect(result, isNull);
});
});
Expand All @@ -119,36 +118,44 @@ void main() {
class FakePathProviderPlatform extends Fake
with MockPlatformInterfaceMixin
implements PathProviderPlatform {
@override
Future<String?> getTemporaryPath() async {
return kTemporaryPath;
}

@override
Future<String?> getApplicationSupportPath() async {
return kApplicationSupportPath;
}

@override
Future<String?> getLibraryPath() async {
return kLibraryPath;
}

@override
Future<String?> getApplicationDocumentsPath() async {
return kApplicationDocumentsPath;
}

@override
Future<String?> getExternalStoragePath() async {
return kExternalStoragePath;
}

@override
Future<List<String>?> getExternalCachePaths() async {
return <String>[kExternalCachePath];
}

@override
Future<List<String>?> getExternalStoragePaths({
StorageDirectory? type,
}) async {
return <String>[kExternalStoragePath];
}

@override
Future<String?> getDownloadsPath() async {
return kDownloadsPath;
}
Expand All @@ -157,36 +164,44 @@ class FakePathProviderPlatform extends Fake
class AllNullFakePathProviderPlatform extends Fake
with MockPlatformInterfaceMixin
implements PathProviderPlatform {
@override
Future<String?> getTemporaryPath() async {
return null;
}

@override
Future<String?> getApplicationSupportPath() async {
return null;
}

@override
Future<String?> getLibraryPath() async {
return null;
}

@override
Future<String?> getApplicationDocumentsPath() async {
return null;
}

@override
Future<String?> getExternalStoragePath() async {
return null;
}

@override
Future<List<String>?> getExternalCachePaths() async {
return null;
}

@override
Future<List<String>?> getExternalStoragePaths({
StorageDirectory? type,
}) async {
return null;
}

@override
Future<String?> getDownloadsPath() async {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -67,7 +65,9 @@ class _MyAppState extends State<MyApp> {
// 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;
Expand All @@ -86,7 +86,7 @@ class _MyAppState extends State<MyApp> {
),
body: Center(
child: Column(
children: [
children: <Widget>[
Text('Temp Directory: $_tempDirectory\n'),
Text('Documents Directory: $_documentsDirectory\n'),
Text('Downloads Directory: $_downloadsDirectory\n'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<void>.delayed(const Duration(milliseconds: 20));
await tester.pump();

// Verify that temporary directory is retrieved.
Expand All @@ -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<void>.delayed(const Duration(milliseconds: 20));
await tester.pump();

// Verify that documents directory is retrieved.
Expand All @@ -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<void>.delayed(const Duration(milliseconds: 20));
await tester.pump();

// Verify that downloads directory is retrieved.
Expand All @@ -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<void>.delayed(const Duration(milliseconds: 20));
await tester.pump();

// Verify that Application Support Directory is retrieved.
Expand Down
Loading

0 comments on commit febc3e3

Please sign in to comment.