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

Path provider windows crash fix #3814

Merged
Merged
Show file tree
Hide file tree
Changes from all 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_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.1

* Fix a crash when a known folder can't be located.

## 2.0.0

* Migrate to null safety
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ class PathProviderWindows extends PathProviderPlatform {

@override
Future<String?> getApplicationSupportPath() async {
final String appDataRoot = await getPath(WindowsKnownFolder.RoamingAppData);
final String? appDataRoot =
await getPath(WindowsKnownFolder.RoamingAppData);
if (appDataRoot == null) {
return null;
}
final Directory directory = Directory(
path.join(appDataRoot, _getApplicationSpecificSubdirectory()));
// Ensure that the directory exists if possible, since it will on other
Expand All @@ -114,7 +118,7 @@ class PathProviderWindows extends PathProviderPlatform {
///
/// folderID is a GUID that represents a specific known folder ID, drawn from
/// [WindowsKnownFolder].
Future<String> getPath(String folderID) {
Future<String?> getPath(String folderID) {
final Pointer<Pointer<Utf16>> pathPtrPtr = calloc<Pointer<Utf16>>();
final Pointer<GUID> knownFolderID = calloc<GUID>()..ref.setGUID(folderID);

Expand All @@ -130,6 +134,7 @@ class PathProviderWindows extends PathProviderPlatform {
if (hr == E_INVALIDARG || hr == E_FAIL) {
throw WindowsException(hr);
}
return Future<String?>.value(null);
}

final String path = pathPtrPtr.value.toDartString();
Expand Down
2 changes: 1 addition & 1 deletion packages/path_provider/path_provider_windows/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: path_provider_windows
description: Windows implementation of the path_provider plugin
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_windows
version: 2.0.0
version: 2.0.1

flutter:
plugin:
Expand Down