Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/path_provider/path_provider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.0-nullsafety

* Migrate to null safe.

## 1.6.28

* Drop unused UUID dependency for tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. 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 'dart:async';

import 'dart:io';
Expand Down
40 changes: 20 additions & 20 deletions packages/path_provider/path_provider/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
Future<Directory> _tempDirectory;
Future<Directory> _appSupportDirectory;
Future<Directory> _appLibraryDirectory;
Future<Directory> _appDocumentsDirectory;
Future<Directory> _externalDocumentsDirectory;
Future<List<Directory>> _externalStorageDirectories;
Future<List<Directory>> _externalCacheDirectories;
Future<Directory?>? _tempDirectory;
Future<Directory?>? _appSupportDirectory;
Future<Directory?>? _appLibraryDirectory;
Future<Directory?>? _appDocumentsDirectory;
Future<Directory?>? _externalDocumentsDirectory;
Future<List<Directory>?>? _externalStorageDirectories;
Future<List<Directory>?>? _externalCacheDirectories;

void _requestTempDirectory() {
setState(() {
Expand All @@ -51,13 +51,13 @@ class _MyHomePageState extends State<MyHomePage> {
}

Widget _buildDirectory(
BuildContext context, AsyncSnapshot<Directory> snapshot) {
BuildContext context, AsyncSnapshot<Directory?> snapshot) {
Text text = const Text('');
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
text = Text('Error: ${snapshot.error}');
} else if (snapshot.hasData) {
text = Text('path: ${snapshot.data.path}');
text = Text('path: ${snapshot.data?.path}');
} else {
text = const Text('path unavailable');
}
Expand All @@ -66,14 +66,14 @@ class _MyHomePageState extends State<MyHomePage> {
}

Widget _buildDirectories(
BuildContext context, AsyncSnapshot<List<Directory>> snapshot) {
BuildContext context, AsyncSnapshot<List<Directory>?> snapshot) {
Text text = const Text('');
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
text = Text('Error: ${snapshot.error}');
} else if (snapshot.hasData) {
final String combined =
snapshot.data.map((Directory d) => d.path).join(', ');
final String? combined =
snapshot.data?.map((Directory d) => d.path).join(', ');
text = Text('paths: $combined');
} else {
text = const Text('path unavailable');
Expand Down Expand Up @@ -134,7 +134,7 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: _requestTempDirectory,
),
),
FutureBuilder<Directory>(
FutureBuilder<Directory?>(
future: _tempDirectory, builder: _buildDirectory),
Padding(
padding: const EdgeInsets.all(16.0),
Expand All @@ -143,7 +143,7 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: _requestAppDocumentsDirectory,
),
),
FutureBuilder<Directory>(
FutureBuilder<Directory?>(
future: _appDocumentsDirectory, builder: _buildDirectory),
Padding(
padding: const EdgeInsets.all(16.0),
Expand All @@ -152,7 +152,7 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: _requestAppSupportDirectory,
),
),
FutureBuilder<Directory>(
FutureBuilder<Directory?>(
future: _appSupportDirectory, builder: _buildDirectory),
Padding(
padding: const EdgeInsets.all(16.0),
Expand All @@ -161,7 +161,7 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: _requestAppLibraryDirectory,
),
),
FutureBuilder<Directory>(
FutureBuilder<Directory?>(
future: _appLibraryDirectory, builder: _buildDirectory),
Padding(
padding: const EdgeInsets.all(16.0),
Expand All @@ -172,7 +172,7 @@ class _MyHomePageState extends State<MyHomePage> {
Platform.isIOS ? null : _requestExternalStorageDirectory,
),
),
FutureBuilder<Directory>(
FutureBuilder<Directory?>(
future: _externalDocumentsDirectory, builder: _buildDirectory),
Column(children: <Widget>[
Padding(
Expand All @@ -190,7 +190,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
]),
FutureBuilder<List<Directory>>(
FutureBuilder<List<Directory>?>(
future: _externalStorageDirectories,
builder: _buildDirectories),
Column(children: <Widget>[
Expand All @@ -204,7 +204,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
]),
FutureBuilder<List<Directory>>(
FutureBuilder<List<Directory>?>(
future: _externalCacheDirectories, builder: _buildDirectories),
],
),
Expand Down
4 changes: 2 additions & 2 deletions packages/path_provider/path_provider/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ dev_dependencies:
path: ../../../integration_test
flutter_driver:
sdk: flutter
pedantic: ^1.8.0
pedantic: ^1.10.0-nullsafety

flutter:
uses-material-design: true

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. 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 'dart:async';
import 'dart:convert';
import 'dart:io';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
43 changes: 25 additions & 18 deletions packages/path_provider/path_provider/lib/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ PathProviderPlatform get _platform {
// with a non-default instance.
if (!kIsWeb && PathProviderPlatform.instance is MethodChannelPathProvider) {
if (Platform.isLinux) {
PathProviderPlatform.instance = PathProviderLinux();
// TODO:
//PathProviderPlatform.instance = PathProviderLinux();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be reverted now.

} else if (Platform.isWindows) {
PathProviderPlatform.instance = PathProviderWindows();
}
Expand All @@ -51,8 +52,8 @@ PathProviderPlatform get _platform {
/// 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;
}
Expand All @@ -69,8 +70,8 @@ Future<Directory> getTemporaryDirectory() async {
/// 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;
}
Expand All @@ -83,8 +84,8 @@ Future<Directory> getApplicationSupportDirectory() async {
///
/// 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;
}
Expand All @@ -100,8 +101,8 @@ Future<Directory> getLibraryDirectory() async {
/// 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;
}
Expand All @@ -116,8 +117,8 @@ Future<Directory> getApplicationDocumentsDirectory() async {
/// 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;
}
Expand All @@ -137,8 +138,11 @@ Future<Directory> getExternalStorageDirectory() async {
///
/// 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();
}
Expand All @@ -155,13 +159,16 @@ Future<List<Directory>> getExternalCacheDirectories() async {
///
/// 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();
}
Expand All @@ -171,8 +178,8 @@ Future<List<Directory>> getExternalStorageDirectories({
///
/// 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;
}
Expand Down
16 changes: 8 additions & 8 deletions packages/path_provider/path_provider/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -21,10 +21,10 @@ flutter:
dependencies:
flutter:
sdk: flutter
path_provider_platform_interface: ^1.0.1
path_provider_platform_interface: ^2.0.0-nullsafety
path_provider_macos: ^0.0.4
path_provider_linux: ^0.0.1
path_provider_windows: ^0.0.4
path_provider_linux: ^0.2.0-nullsafety
path_provider_windows: ^0.1.0-nullsafety

dev_dependencies:
integration_test:
Expand All @@ -33,10 +33,10 @@ dev_dependencies:
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"
38 changes: 19 additions & 19 deletions packages/path_provider/path_provider/test/path_provider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,45 @@ void main() {
});

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);
});
});
}
Expand Down Expand Up @@ -99,7 +99,7 @@ class MockPathProviderPlatform extends Mock
}

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