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

Commit 1fe6814

Browse files
author
Emmanuel Garcia
committed
Fixes and new tests
1 parent 730b6cc commit 1fe6814

File tree

10 files changed

+74
-48
lines changed

10 files changed

+74
-48
lines changed

packages/path_provider/path_provider/example/integration_test/path_provider_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,22 @@ import 'dart:async';
99
import 'dart:io';
1010
import 'package:flutter_test/flutter_test.dart';
1111
import 'package:path_provider/path_provider.dart';
12+
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
13+
import 'package:path_provider_linux/path_provider_linux.dart';
14+
import 'package:path_provider_windows/path_provider_windows.dart';
1215
import 'package:integration_test/integration_test.dart';
1316

1417
void main() {
1518
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
1619

20+
test('path provider instance on Windows', () {
21+
expect(PathProviderPlatform.instance, isA<PathProviderWindows>());
22+
}, skip: !Platform.isWindows);
23+
24+
test('path provider instance on Linux', () {
25+
expect(PathProviderPlatform.instance, isA<PathProviderLinux>());
26+
}, skip: !Platform.isLinux);
27+
1728
testWidgets('getTemporaryDirectory', (WidgetTester tester) async {
1829
final Directory result = await getTemporaryDirectory();
1930
_verifySampleFile(result, 'temporaryDirectory');

packages/path_provider/path_provider/example/pubspec.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ dependencies:
1212
# the parent directory to use the current plugin's version.
1313
path: ../
1414

15+
# TODO(egarciad): Remove the overrides once the packages are published.
16+
dependency_overrides:
17+
path_provider_macos:
18+
path: ../../path_provider_macos
19+
path_provider_linux:
20+
path: ../../path_provider_linux
21+
path_provider_windows:
22+
path: ../../path_provider_windows
23+
1524
dev_dependencies:
1625
integration_test:
1726
path: ../../../integration_test

packages/path_provider/path_provider/lib/path_provider.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6-
import 'dart:io' show Directory, Platform;
6+
import 'dart:io' show Directory;
77

8-
import 'package:flutter/foundation.dart' show kIsWeb, visibleForTesting;
9-
import 'package:path_provider_linux/path_provider_linux.dart';
10-
import 'package:path_provider_windows/path_provider_windows.dart';
8+
import 'package:flutter/foundation.dart' show visibleForTesting;
119
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
12-
import 'package:path_provider_platform_interface/src/method_channel_path_provider.dart';
1310

1411
export 'package:path_provider_platform_interface/path_provider_platform_interface.dart'
1512
show StorageDirectory;
@@ -76,7 +73,8 @@ Future<Directory> getTemporaryDirectory() async {
7673
/// Throws a `MissingPlatformDirectoryException` if the system is unable to
7774
/// provide the directory.
7875
Future<Directory> getApplicationSupportDirectory() async {
79-
final String? path = await PathProviderPlatform.instance.getApplicationSupportPath();
76+
final String? path =
77+
await PathProviderPlatform.instance.getApplicationSupportPath();
8078
if (path == null) {
8179
throw MissingPlatformDirectoryException(
8280
'Unable to get application support directory');
@@ -114,7 +112,8 @@ Future<Directory> getLibraryDirectory() async {
114112
/// Throws a `MissingPlatformDirectoryException` if the system is unable to
115113
/// provide the directory.
116114
Future<Directory> getApplicationDocumentsDirectory() async {
117-
final String? path = await PathProviderPlatform.instance.getApplicationDocumentsPath();
115+
final String? path =
116+
await PathProviderPlatform.instance.getApplicationDocumentsPath();
118117
if (path == null) {
119118
throw MissingPlatformDirectoryException(
120119
'Unable to get application documents directory');
@@ -131,7 +130,8 @@ Future<Directory> getApplicationDocumentsDirectory() async {
131130
///
132131
/// On Android this uses the `getExternalFilesDir(null)`.
133132
Future<Directory?> getExternalStorageDirectory() async {
134-
final String? path = await PathProviderPlatform.instance.getExternalStoragePath();
133+
final String? path =
134+
await PathProviderPlatform.instance.getExternalStoragePath();
135135
if (path == null) {
136136
return null;
137137
}
@@ -152,7 +152,8 @@ Future<Directory?> getExternalStorageDirectory() async {
152152
/// On Android this returns Context.getExternalCacheDirs() or
153153
/// Context.getExternalCacheDir() on API levels below 19.
154154
Future<List<Directory>?> getExternalCacheDirectories() async {
155-
final List<String>? paths = await PathProviderPlatform.instance.getExternalCachePaths();
155+
final List<String>? paths =
156+
await PathProviderPlatform.instance.getExternalCachePaths();
156157
if (paths == null) {
157158
return null;
158159
}

packages/path_provider/path_provider/pubspec.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ dependencies:
2626
path_provider_linux: ^2.0.0
2727
path_provider_windows: ^2.0.0
2828

29-
# TODO(egarciad): Bump dependencies above and remove the overrides.
30-
dependency_overrides:
31-
path_provider_macos:
32-
path: ../path_provider_macos
33-
path_provider_linux:
34-
path: ../path_provider_linux
35-
path_provider_windows:
36-
path: ../path_provider_windows
37-
3829
dev_dependencies:
3930
integration_test:
4031
path: ../../integration_test

packages/path_provider/path_provider_windows/lib/src/path_provider_windows_stub.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import 'package:path_provider_platform_interface/path_provider_platform_interfac
1212
/// path_provider will also depend on path_provider_windows, not just at the
1313
/// pubspec level but the code level.
1414
class PathProviderWindows extends PathProviderPlatform {
15+
/// Registers the Windows implementation.
16+
static void registerWith() {
17+
PathProviderPlatform.instance = PathProviderWindows();
18+
}
19+
1520
/// Errors on attempted instantiation of the stub. It exists only to satisfy
1621
/// compile-time dependencies, and should never actually be created.
1722
PathProviderWindows() {

packages/shared_preferences/shared_preferences/example/pubspec.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ dev_dependencies:
1919
path: ../../../integration_test
2020
pedantic: ^1.10.0
2121

22+
# TODO(egarciad): Bump dependencies above and remove the overrides.
23+
dependency_overrides:
24+
shared_preferences_linux:
25+
path: ../../shared_preferences_linux
26+
shared_preferences_macos:
27+
path: ../../shared_preferences_macos
28+
shared_preferences_windows:
29+
path: ../../shared_preferences_windows
30+
2231
flutter:
2332
uses-material-design: true
2433

packages/shared_preferences/shared_preferences/lib/shared_preferences.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6-
import 'dart:io' show Platform;
76

8-
import 'package:flutter/foundation.dart' show kIsWeb;
97
import 'package:meta/meta.dart';
10-
import 'package:shared_preferences_linux/shared_preferences_linux.dart';
11-
import 'package:shared_preferences_platform_interface/method_channel_shared_preferences.dart';
128
import 'package:shared_preferences_platform_interface/shared_preferences_platform_interface.dart';
13-
import 'package:shared_preferences_windows/shared_preferences_windows.dart';
149

1510
/// Wraps NSUserDefaults (on iOS) and SharedPreferences (on Android), providing
1611
/// a persistent store for simple data.
@@ -21,7 +16,6 @@ class SharedPreferences {
2116

2217
static const String _prefix = 'flutter.';
2318
static Completer<SharedPreferences>? _completer;
24-
static bool _manualDartRegistrationNeeded = true;
2519

2620
/// Loads and parses the [SharedPreferences] for this app from disk.
2721
///
@@ -130,7 +124,8 @@ class SharedPreferences {
130124
} else {
131125
_preferenceCache[key] = value;
132126
}
133-
return SharedPreferencesStorePlatform.instance.setValue(valueType, prefixedKey, value);
127+
return SharedPreferencesStorePlatform.instance
128+
.setValue(valueType, prefixedKey, value);
134129
}
135130

136131
/// Always returns true.

packages/shared_preferences/shared_preferences/pubspec.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ dependencies:
3434
shared_preferences_web: ^2.0.0
3535
shared_preferences_windows: ^2.0.0
3636

37-
# TODO(egarciad): Bump dependencies above and remove the overrides.
38-
dependency_overrides:
39-
shared_preferences_linux:
40-
path: ../shared_preferences_linux
41-
shared_preferences_macos:
42-
path: ../shared_preferences_macos
43-
shared_preferences_windows:
44-
path: ../shared_preferences_windows
45-
46-
4737
dev_dependencies:
4838
flutter_test:
4939
sdk: flutter

packages/shared_preferences/shared_preferences_linux/example/integration_test/shared_preferences_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ void main() {
3636
preferences = SharedPreferencesLinux();
3737
});
3838

39-
tearDown(() {
40-
preferences.clear();
39+
tearDown(() async {
40+
await preferences.clear();
4141
});
4242

4343
testWidgets('reading', (WidgetTester _) async {

packages/shared_preferences/shared_preferences_windows/example/integration_test/shared_preferences_test.dart

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
// @dart=2.9
66

7-
import 'dart:async';
87
import 'package:flutter_test/flutter_test.dart';
98
import 'package:shared_preferences_windows/shared_preferences_windows.dart';
109
import 'package:integration_test/integration_test.dart';
@@ -31,12 +30,12 @@ void main() {
3130

3231
SharedPreferencesWindows preferences;
3332

34-
setUp(() async {
33+
setUp(() {
3534
preferences = SharedPreferencesWindows();
3635
});
3736

38-
tearDown(() {
39-
preferences.clear();
37+
tearDown(() async {
38+
expect(await preferences.clear(), isTrue);
4039
});
4140

4241
testWidgets('reading', (WidgetTester _) async {
@@ -49,15 +48,31 @@ void main() {
4948
});
5049

5150
testWidgets('writing', (WidgetTester _) async {
52-
await Future.wait(<Future<bool>>[
53-
preferences.setValue(
51+
expect(
52+
await preferences.setValue(
5453
'String', 'String', kTestValues2['flutter.String']),
55-
preferences.setValue('Bool', 'bool', kTestValues2['flutter.bool']),
56-
preferences.setValue('Int', 'int', kTestValues2['flutter.int']),
57-
preferences.setValue(
54+
isTrue,
55+
);
56+
expect(
57+
await preferences.setValue(
58+
'Bool', 'bool', kTestValues2['flutter.bool']),
59+
isTrue,
60+
);
61+
expect(
62+
await preferences.setValue('Int', 'int', kTestValues2['flutter.int']),
63+
isTrue,
64+
);
65+
expect(
66+
await preferences.setValue(
5867
'Double', 'double', kTestValues2['flutter.double']),
59-
preferences.setValue('StringList', 'List', kTestValues2['flutter.List'])
60-
]);
68+
isTrue,
69+
);
70+
expect(
71+
await preferences.setValue(
72+
'StringList', 'List', kTestValues2['flutter.List']),
73+
isTrue,
74+
);
75+
6176
final Map<String, Object> values = await preferences.getAll();
6277
expect(values['String'], kTestValues2['flutter.String']);
6378
expect(values['bool'], kTestValues2['flutter.bool']);

0 commit comments

Comments
 (0)