@@ -22,20 +22,19 @@ import 'folders.dart';
2222class VersionInfoQuerier {
2323 /// Returns the value for [key] in [versionInfo] s English strings section, or
2424 /// null if there is no such entry, or if versionInfo is null.
25- getStringValue (Pointer <Uint8 > versionInfo, key) {
25+ getStringValue (Pointer <Uint8 >? versionInfo, key) {
2626 if (versionInfo == null ) {
2727 return null ;
2828 }
2929 const kEnUsLanguageCode = '040904e4' ;
3030 final keyPath = TEXT ('\\ StringFileInfo\\ $kEnUsLanguageCode \\ $key ' );
3131 final length = allocate <Uint32 >();
32- final valueAddress = allocate <IntPtr >();
32+ final valueAddress = allocate <Pointer < Utf16 > >();
3333 try {
3434 if (VerQueryValue (versionInfo, keyPath, valueAddress, length) == 0 ) {
3535 return null ;
3636 }
37- return Pointer <Utf16 >.fromAddress (valueAddress.value)
38- .unpackString (length.value);
37+ return valueAddress.value.unpackString (length.value);
3938 } finally {
4039 free (keyPath);
4140 free (length);
@@ -54,7 +53,7 @@ class PathProviderWindows extends PathProviderPlatform {
5453
5554 /// This is typically the same as the TMP environment variable.
5655 @override
57- Future <String > getTemporaryPath () async {
56+ Future <String ? > getTemporaryPath () async {
5857 final buffer = allocate <Uint16 >(count: MAX_PATH + 1 ).cast <Utf16 >();
5958 String path;
6059
@@ -88,7 +87,7 @@ class PathProviderWindows extends PathProviderPlatform {
8887 }
8988
9089 @override
91- Future <String > getApplicationSupportPath () async {
90+ Future <String ? > getApplicationSupportPath () async {
9291 final appDataRoot = await getPath (WindowsKnownFolder .RoamingAppData );
9392 final directory = Directory (
9493 path.join (appDataRoot, _getApplicationSpecificSubdirectory ()));
@@ -105,25 +104,23 @@ class PathProviderWindows extends PathProviderPlatform {
105104 }
106105
107106 @override
108- Future <String > getApplicationDocumentsPath () =>
107+ Future <String ? > getApplicationDocumentsPath () =>
109108 getPath (WindowsKnownFolder .Documents );
110109
111110 @override
112- Future <String > getDownloadsPath () => getPath (WindowsKnownFolder .Downloads );
111+ Future <String ? > getDownloadsPath () => getPath (WindowsKnownFolder .Downloads );
113112
114113 /// Retrieve any known folder from Windows.
115114 ///
116115 /// folderID is a GUID that represents a specific known folder ID, drawn from
117116 /// [WindowsKnownFolder] .
118117 Future <String > getPath (String folderID) {
119- final pathPtrPtr = allocate <IntPtr >();
120- Pointer <Utf16 > pathPtr ;
118+ final pathPtrPtr = allocate <Pointer < Utf16 > >();
119+ final Pointer <GUID > knownFolderID = calloc < GUID >().. setGUID (folderID) ;
121120
122121 try {
123- GUID knownFolderID = GUID .fromString (folderID);
124-
125122 final hr = SHGetKnownFolderPath (
126- knownFolderID.addressOf, // ignore: deprecated_member_use
123+ knownFolderID,
127124 KF_FLAG_DEFAULT ,
128125 NULL ,
129126 pathPtrPtr,
@@ -135,12 +132,11 @@ class PathProviderWindows extends PathProviderPlatform {
135132 }
136133 }
137134
138- pathPtr = Pointer <Utf16 >.fromAddress (pathPtrPtr.value);
139- final path = pathPtr.unpackString (MAX_PATH );
135+ final path = pathPtrPtr.value.unpackString (MAX_PATH );
140136 return Future .value (path);
141137 } finally {
142- CoTaskMemFree (pathPtr.cast ());
143138 free (pathPtrPtr);
139+ free (knownFolderID);
144140 }
145141 }
146142
@@ -155,13 +151,13 @@ class PathProviderWindows extends PathProviderPlatform {
155151 /// - If the product name isn't there, it will use the exe's filename (without
156152 /// extension).
157153 String _getApplicationSpecificSubdirectory () {
158- String companyName;
159- String productName;
154+ String ? companyName;
155+ String ? productName;
160156
161157 final Pointer <Utf16 > moduleNameBuffer =
162158 allocate <Uint16 >(count: MAX_PATH + 1 ).cast <Utf16 >();
163159 final Pointer <Uint32 > unused = allocate <Uint32 >();
164- Pointer <Uint8 > infoBuffer;
160+ Pointer <Uint8 >? infoBuffer;
165161 try {
166162 // Get the module name.
167163 final moduleNameLength = GetModuleFileName (0 , moduleNameBuffer, MAX_PATH );
@@ -207,7 +203,7 @@ class PathProviderWindows extends PathProviderPlatform {
207203 /// https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
208204 ///
209205 /// If after sanitizing the string is empty, returns null.
210- String _sanitizedDirectoryName (String rawString) {
206+ String ? _sanitizedDirectoryName (String ? rawString) {
211207 if (rawString == null ) {
212208 return null ;
213209 }
0 commit comments