From a5ed06fe5974d7ec58a0e61382fb4a45751c4352 Mon Sep 17 00:00:00 2001 From: DatDang Date: Tue, 11 Jun 2024 15:28:44 +0700 Subject: [PATCH 1/2] Release picked file data for Web --- CHANGELOG.md | 4 ++++ lib/_internal/file_picker_web.dart | 6 ++++++ pubspec.yaml | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bccfaeea..fba10fe9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 8.0.5 +### Web +Release picked file data in memory to avoid memory leak + ## 8.0.4 ### Android Removes references to Flutter v1 android embedding classes. diff --git a/lib/_internal/file_picker_web.dart b/lib/_internal/file_picker_web.dart index f43f127a..0287f20d 100644 --- a/lib/_internal/file_picker_web.dart +++ b/lib/_internal/file_picker_web.dart @@ -169,6 +169,12 @@ class FilePickerWeb extends FilePicker { _target.children.add(uploadInput); uploadInput.click(); + firstChild = _target.firstChild; + while (firstChild != null) { + _target.removeChild(firstChild); + firstChild = _target.firstChild; + } + final List? files = await filesCompleter.future; return files == null ? null : FilePickerResult(files); diff --git a/pubspec.yaml b/pubspec.yaml index 42771cb2..6147c99a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker repository: https://github.com/miguelpruivo/flutter_file_picker issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues -version: 8.0.4 +version: 8.0.5 dependencies: flutter: From 9c6cba915b0d17b7ccba182d1263e35d37214a9d Mon Sep 17 00:00:00 2001 From: DatDang Date: Tue, 11 Jun 2024 16:51:20 +0700 Subject: [PATCH 2/2] Update deprecated properties for file picker windows --- lib/src/windows/file_picker_windows.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/src/windows/file_picker_windows.dart b/lib/src/windows/file_picker_windows.dart index a5b92c94..ee5babe6 100644 --- a/lib/src/windows/file_picker_windows.dart +++ b/lib/src/windows/file_picker_windows.dart @@ -94,7 +94,9 @@ class FilePickerWindows extends FilePicker { String? initialDirectory, }) { int hr = CoInitializeEx( - nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); + nullptr, + COINIT.COINIT_APARTMENTTHREADED | COINIT.COINIT_DISABLE_OLE1DDE, + ); if (!SUCCEEDED(hr)) throw WindowsException(hr); @@ -134,7 +136,7 @@ class FilePickerWindows extends FilePicker { if (!SUCCEEDED(hr)) { CoUninitialize(); - if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { + if (hr == HRESULT_FROM_WIN32(WIN32_ERROR.ERROR_CANCELLED)) { return Future.value(null); } throw WindowsException(hr);