Migrate path_provider to null safety. (#3460)

diff --git a/packages/path_provider/path_provider/CHANGELOG.md b/packages/path_provider/path_provider/CHANGELOG.md
index 43e765a..7364305 100644
--- a/packages/path_provider/path_provider/CHANGELOG.md
+++ b/packages/path_provider/path_provider/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 2.0.0-nullsafety
+
+* Migrate to null safety.
+
 ## 1.6.28
 
 * Drop unused UUID dependency for tests.
diff --git a/packages/path_provider/path_provider/integration_test/path_provider_test.dart b/packages/path_provider/path_provider/integration_test/path_provider_test.dart
index 18570ae..da368d5 100644
--- a/packages/path_provider/path_provider/integration_test/path_provider_test.dart
+++ b/packages/path_provider/path_provider/integration_test/path_provider_test.dart
@@ -1,3 +1,9 @@
+// Copyright 2019 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.
+
+// @dart=2.9
+
 import 'package:flutter_test/flutter_test.dart';
 import 'package:path_provider/path_provider.dart';
 import 'package:integration_test/integration_test.dart';
diff --git a/packages/path_provider/path_provider/lib/path_provider.dart b/packages/path_provider/path_provider/lib/path_provider.dart
index 0fbab57..1560c33 100644
--- a/packages/path_provider/path_provider/lib/path_provider.dart
+++ b/packages/path_provider/path_provider/lib/path_provider.dart
@@ -51,8 +51,8 @@
 /// On iOS, this uses the `NSCachesDirectory` API.
 ///
 /// On Android, this uses the `getCacheDir` API on the context.
-Future<Directory> getTemporaryDirectory() async {
-  final String path = await _platform.getTemporaryPath();
+Future<Directory?> getTemporaryDirectory() async {
+  final String? path = await _platform.getTemporaryPath();
   if (path == null) {
     return null;
   }
@@ -69,8 +69,8 @@
 /// If this directory does not exist, it is created automatically.
 ///
 /// On Android, this function uses the `getFilesDir` API on the context.
-Future<Directory> getApplicationSupportDirectory() async {
-  final String path = await _platform.getApplicationSupportPath();
+Future<Directory?> getApplicationSupportDirectory() async {
+  final String? path = await _platform.getApplicationSupportPath();
   if (path == null) {
     return null;
   }
@@ -83,8 +83,8 @@
 ///
 /// On Android, this function throws an [UnsupportedError] as no equivalent
 /// path exists.
-Future<Directory> getLibraryDirectory() async {
-  final String path = await _platform.getLibraryPath();
+Future<Directory?> getLibraryDirectory() async {
+  final String? path = await _platform.getLibraryPath();
   if (path == null) {
     return null;
   }
@@ -100,8 +100,8 @@
 /// On Android, this uses the `getDataDirectory` API on the context. Consider
 /// using [getExternalStorageDirectory] instead if data is intended to be visible
 /// to the user.
-Future<Directory> getApplicationDocumentsDirectory() async {
-  final String path = await _platform.getApplicationDocumentsPath();
+Future<Directory?> getApplicationDocumentsDirectory() async {
+  final String? path = await _platform.getApplicationDocumentsPath();
   if (path == null) {
     return null;
   }
@@ -116,8 +116,8 @@
 /// to access outside the app's sandbox.
 ///
 /// On Android this uses the `getExternalFilesDir(null)`.
-Future<Directory> getExternalStorageDirectory() async {
-  final String path = await _platform.getExternalStoragePath();
+Future<Directory?> getExternalStorageDirectory() async {
+  final String? path = await _platform.getExternalStoragePath();
   if (path == null) {
     return null;
   }
@@ -137,8 +137,11 @@
 ///
 /// On Android this returns Context.getExternalCacheDirs() or
 /// Context.getExternalCacheDir() on API levels below 19.
-Future<List<Directory>> getExternalCacheDirectories() async {
-  final List<String> paths = await _platform.getExternalCachePaths();
+Future<List<Directory>?> getExternalCacheDirectories() async {
+  final List<String>? paths = await _platform.getExternalCachePaths();
+  if (paths == null) {
+    return null;
+  }
 
   return paths.map((String path) => Directory(path)).toList();
 }
@@ -155,13 +158,16 @@
 ///
 /// On Android this returns Context.getExternalFilesDirs(String type) or
 /// Context.getExternalFilesDir(String type) on API levels below 19.
-Future<List<Directory>> getExternalStorageDirectories({
+Future<List<Directory>?> getExternalStorageDirectories({
   /// Optional parameter. See [StorageDirectory] for more informations on
   /// how this type translates to Android storage directories.
-  StorageDirectory type,
+  StorageDirectory? type,
 }) async {
-  final List<String> paths =
+  final List<String>? paths =
       await _platform.getExternalStoragePaths(type: type);
+  if (paths == null) {
+    return null;
+  }
 
   return paths.map((String path) => Directory(path)).toList();
 }
@@ -171,8 +177,8 @@
 ///
 /// On Android and on iOS, this function throws an [UnsupportedError] as no equivalent
 /// path exists.
-Future<Directory> getDownloadsDirectory() async {
-  final String path = await _platform.getDownloadsPath();
+Future<Directory?> getDownloadsDirectory() async {
+  final String? path = await _platform.getDownloadsPath();
   if (path == null) {
     return null;
   }
diff --git a/packages/path_provider/path_provider/pubspec.yaml b/packages/path_provider/path_provider/pubspec.yaml
index 065c53f..6c4c851 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: 1.6.28
+version: 2.0.0-nullsafety
 
 flutter:
   plugin:
@@ -21,10 +21,10 @@
 dependencies:
   flutter:
     sdk: flutter
-  path_provider_platform_interface: ^1.0.1
-  path_provider_macos: ^0.0.4
-  path_provider_linux: ^0.0.1
-  path_provider_windows: ^0.0.4
+  path_provider_platform_interface: ^2.0.0-nullsafety
+  path_provider_macos: ^0.0.5-nullsafety
+  path_provider_linux: ^0.2.0-nullsafety
+  path_provider_windows: ^0.1.0-nullsafety
 
 dev_dependencies:
   integration_test:
@@ -33,10 +33,10 @@
     sdk: flutter
   flutter_driver:
     sdk: flutter
-  pedantic: ^1.8.0
-  mockito: ^4.1.1
-  plugin_platform_interface: ^1.0.0
+  pedantic: ^1.10.0-nullsafety
+  mockito: ^5.0.0-nullsafety.0
+  plugin_platform_interface: ^1.1.0-nullsafety
 
 environment:
-  sdk: ">=2.1.0 <3.0.0"
+  sdk: ">=2.12.0-0 <3.0.0"
   flutter: ">=1.12.13+hotfix.5"
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 eb17178..aec5e06 100644
--- a/packages/path_provider/path_provider/test/path_provider_test.dart
+++ b/packages/path_provider/path_provider/test/path_provider_test.dart
@@ -28,45 +28,45 @@
     });
 
     test('getTemporaryDirectory', () async {
-      Directory result = await getTemporaryDirectory();
-      expect(result.path, kTemporaryPath);
+      Directory? result = await getTemporaryDirectory();
+      expect(result?.path, kTemporaryPath);
     });
 
     test('getApplicationSupportDirectory', () async {
-      Directory result = await getApplicationSupportDirectory();
-      expect(result.path, kApplicationSupportPath);
+      Directory? result = await getApplicationSupportDirectory();
+      expect(result?.path, kApplicationSupportPath);
     });
 
     test('getLibraryDirectory', () async {
-      Directory result = await getLibraryDirectory();
-      expect(result.path, kLibraryPath);
+      Directory? result = await getLibraryDirectory();
+      expect(result?.path, kLibraryPath);
     });
 
     test('getApplicationDocumentsDirectory', () async {
-      Directory result = await getApplicationDocumentsDirectory();
-      expect(result.path, kApplicationDocumentsPath);
+      Directory? result = await getApplicationDocumentsDirectory();
+      expect(result?.path, kApplicationDocumentsPath);
     });
 
     test('getExternalStorageDirectory', () async {
-      Directory result = await getExternalStorageDirectory();
-      expect(result.path, kExternalStoragePath);
+      Directory? result = await getExternalStorageDirectory();
+      expect(result?.path, kExternalStoragePath);
     });
 
     test('getExternalCacheDirectories', () async {
-      List<Directory> result = await getExternalCacheDirectories();
-      expect(result.length, 1);
-      expect(result.first.path, kExternalCachePath);
+      List<Directory>? result = await getExternalCacheDirectories();
+      expect(result?.length, 1);
+      expect(result?.first.path, kExternalCachePath);
     });
 
     test('getExternalStorageDirectories', () async {
-      List<Directory> result = await getExternalStorageDirectories();
-      expect(result.length, 1);
-      expect(result.first.path, kExternalStoragePath);
+      List<Directory>? result = await getExternalStorageDirectories();
+      expect(result?.length, 1);
+      expect(result?.first.path, kExternalStoragePath);
     });
 
     test('getDownloadsDirectory', () async {
-      Directory result = await getDownloadsDirectory();
-      expect(result.path, kDownloadsPath);
+      Directory? result = await getDownloadsDirectory();
+      expect(result?.path, kDownloadsPath);
     });
   });
 }
@@ -99,7 +99,7 @@
   }
 
   Future<List<String>> getExternalStoragePaths({
-    StorageDirectory type,
+    StorageDirectory? type,
   }) async {
     return <String>[kExternalStoragePath];
   }