First, thank you for the excellent library - it really seems to be the only one out there that performs this function. Now, on to the problem ;)
I'm trying use the saveAs method on MacOS and I'm getting a funky error after clicking save. The file seems to save properly to the specified location, but throws an error at the end. I spent a number of hours trying to trace the root of the error without any luck. It appears to be coming from the Flutter foundation code, or perhaps the FlutterMacOS code. The fileSave method works fine without any problems, but I want my users to specify the location of the file to be saved, so I need the dialog box. After the error, the method does not seems to return as the Path is not provided.
It doesn't seem to matter what data is saved, or which mime type - it always generates this error.
Unrelated, I would expect this method call to return a valid path without saving when the user selects 'save', but instead it saves the file. The source code backs that up -- it is odd to return the path and save the file. I would expect the path to be returned and let me save separately to the path.
Sample code and stack trace below:
SAMPLE CODE:
void _saveBoard() async {
logger.d("Save board");
if (!kIsWeb) {
if (Platform.isIOS || Platform.isAndroid || Platform.isMacOS) {
// This does NOT work on MacOS!
// bool status = await Permission.storage.isGranted;
// if (!status) await Permission.storage.request();
MimeType type = MimeType.TEXT;
String test = '{"version": 20220601,"costs": { "Walnut": 12.99}}';
Uint8List data = Uint8List.fromList(test.codeUnits);
String path =
await FileSaver.instance.saveAs("File", data, "json", type);
logger.d("File Path: $path");
// await FileSaver.instance.saveFile("test", data, "txt");
}
}
logger.d("Complete _saveBoard");
}
STACK TRACE:
Reloaded 1 of 1086 libraries in 326ms.
flutter: [DEBUG ] MyToolbar._saveBoard: Save board
2022-06-02 17:04:20.587 Cutting Board Builder[30991:5328835] Unsupported value: file:///Users/user/Desktop/test.json of type NSURL
2022-06-02 17:04:20.587 Cutting Board Builder[30991:5328835] *** Assertion failure in -[FlutterStandardWriter writeValue:], FlutterStandardCodec.mm:338
2022-06-02 17:04:20.590 Cutting Board Builder[30991:5328835] -[NSSavePanel didEndPanelWithReturnCode:] caught non-fatal NSInternalInconsistencyException 'Unsupported value for standard codec' with user dictionary {
NSAssertFile = "FlutterStandardCodec.mm";
NSAssertLine = 338;
} and backtrace (
0 CoreFoundation 0x00007ff80e8087b3 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007ff80e568bc3 objc_exception_throw + 48
2 Foundation 0x00007ff80f6bad13 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 267
3 FlutterMacOS 0x00000001099fb617 -[FlutterStandardWriter writeValue:] + 999
4 FlutterMacOS 0x00000001099fa1b5 -[FlutterStandardMethodCodec encodeSuccessEnvelope:] + 117
5 FlutterMacOS 0x00000001099f7e5a __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke_2 + 154
6 file_saver 0x000000010619c2ee $syXlSgIeyBy_ypSgIegn_TR + 190
7 file_saver 0x000000010619a519 $s10file_saver6DialogC8saveFile33_D4C5CDA81D09C203BAC31A1F4939CEC0LL8byteData3url0A4Name3ext6resultySays5UInt8VG_10Foundation3URLVS2SyypSgctF + 441
8 file_saver 0x000000010619a162 $s10file_saver6DialogC010openSaveAsC06params6resultyAA6ParamsV_yypSgctFySo15NSModalResponseacfU_ + 1138
9 file_saver 0x000000010619a2d0 $sSo15NSModalResponseaIegy_ABIeyBy_TR + 48
10 AppKit 0x00007ff811bd420e -[NSSavePanel didEndPanelWithReturnCode:] + 76
11 AppKit 0x00007ff811bd4460 -[NSSavePanel completeModeless:] + 23
12 AppKit 0x00007ff811bd4769 -[NSSavePanel completeWithReturnCode:url:urls:] + 449
13 AppKit 0x00007ff811bd679a -[NSSavePanel observeValueForKeyPath:ofObject:change:context:] + 325
14 Foundation 0x00007ff80f5c31aa NSKeyValueNotifyObserver + 306
15 Foundation 0x00007ff80f6870b9 NSKeyValueDidChange + 431
16 Foundation 0x00007ff80f72f84e NSKeyValueDidChangeWithPerThreadPendingNotifications + 146
17 ViewBridge 0x00007ff815cf6091 __41-[NSViewBridge setObject:forKey:withKVO:]_block_invoke + 360
18 ViewBridge 0x00007ff815d76701 withHintInProgress + 198
19 ViewBridge 0x00007ff815cedf77 -[NSViewBridge setObject:forKey:withKVO:] + 417
20 ViewBridge 0x00007ff815cef1cc -[NSViewBridge nonLocalChangeInProgress:block:] + 172
21 ViewBridge 0x00007ff815ceef8c -[NSRemoteViewMarshal exceptionSafeSetRemoteObject:forKey:withReply:] + 264
22 ViewBridge 0x00007ff815ceee42 -[NSRemoteViewMarshal setRemoteObject:forKey:withReply:] + 56
23 CoreFoundation 0x00007ff80e7709cc __invoking___ + 140
24 CoreFoundation 0x00007ff80e770873 -[NSInvocation invoke] + 305
25 ViewBridge 0x00007ff815cecf00 __deferNSXPCInvocationOntoMainThread_block_invoke + 228
26 ViewBridge 0x00007ff815ce02c4 __wrapBlockWithVoucher_block_invoke + 37
27 ViewBridge 0x00007ff815cdff4f __deferBlockOntoMainThread_block_invoke_2 + 274
28 CoreFoundation 0x00007ff80e78cd31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
29 CoreFoundation 0x00007ff80e78cbdc __CFRunLoopDoBlocks + 445
30 CoreFoundation 0x00007ff80e78bf4d __CFRunLoopRun + 2609
31 CoreFoundation 0x00007ff80e78ae5c CFRunLoopRunSpecific + 562
32 HIToolbox 0x00007ff8174325e6 RunCurrentEventLoopInMode + 292
33 HIToolbox 0x00007ff81743234a ReceiveNextEventCommon + 594
34 HIToolbox 0x00007ff8174320e5 _BlockUntilNextEventMatchingListInModeWithFilter + 70
35 AppKit 0x00007ff8111ca1fd _DPSNextEvent + 927
36 AppKit 0x00007ff8111c88ba -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1394
37 AppKit 0x00007ff8113cc810 -[NSWindow(NSEventRouting) trackEventsMatchingMask:timeout:mode:handler:] + 261
38 ViewBridge 0x00007ff815d53e98 -[NSRemoteView _beginTrackingLoop:reply:] + 379
39 ViewBridge 0x00007ff815d56be4 -[NSRemoteViewMarshal beginTrackingLoop:reply:] + 48
40 CoreFoundation 0x00007ff80e7709cc __invoking___ + 140
41 CoreFoundation 0x00007ff80e770873 -[NSInvocation invoke] + 305
42 ViewBridge 0x00007ff815cecf00 __deferNSXPCInvocationOntoMainThread_block_invoke + 228
43 ViewBridge 0x00007ff815ce02c4 __wrapBlockWithVoucher_block_invoke + 37
44 ViewBridge 0x00007ff815cdff4f __deferBlockOntoMainThread_block_invoke_2 + 274
45 CoreFoundation 0x00007ff80e78cd31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
46 CoreFoundation 0x00007ff80e78cbdc __CFRunLoopDoBlocks + 445
47 CoreFoundation 0x00007ff80e78bf4d __CFRunLoopRun + 2609
48 CoreFoundation 0x00007ff80e78ae5c CFRunLoopRunSpecific + 562
49 HIToolbox 0x00007ff8174325e6 RunCurrentEventLoopInMode + 292
50 HIToolbox 0x00007ff81743234a ReceiveNextEventCommon + 594
51 HIToolbox 0x00007ff8174320e5 _BlockUntilNextEventMatchingListInModeWithFilter + 70
52 AppKit 0x00007ff8111ca1fd _DPSNextEvent + 927
53 AppKit 0x00007ff8111c88ba -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1394
54 AppKit 0x00007ff8111baf69 -[NSApplication run] + 586
55 AppKit 0x00007ff81118eee7 NSApplicationMain + 817
56 Cutting Board Builder 0x00000001060659e9 main + 9
57 dyld 0x000000010e03351e start + 462
)
2022-06-02 17:04:20.593 Cutting Board Builder[30991:5328835] -[NSSavePanel observeValueForKeyPath:ofObject:change:context:] caught non-fatal NSInternalInconsistencyException 'Unsupported value for standard codec' with user dictionary {
NSAssertFile = "FlutterStandardCodec.mm";
NSAssertLine = 338;
} and backtrace (
0 CoreFoundation 0x00007ff80e8087b3 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007ff80e568bc3 objc_exception_throw + 48
2 Foundation 0x00007ff80f6bad13 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 267
3 FlutterMacOS 0x00000001099fb617 -[FlutterStandardWriter writeValue:] + 999
4 FlutterMacOS 0x00000001099fa1b5 -[FlutterStandardMethodCodec encodeSuccessEnvelope:] + 117
5 FlutterMacOS 0x00000001099f7e5a __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke_2 + 154
6 file_saver 0x000000010619c2ee $syXlSgIeyBy_ypSgIegn_TR + 190
7 file_saver 0x000000010619a519 $s10file_saver6DialogC8saveFile33_D4C5CDA81D09C203BAC31A1F4939CEC0LL8byteData3url0A4Name3ext6resultySays5UInt8VG_10Foundation3URLVS2SyypSgctF + 441
8 file_saver 0x000000010619a162 $s10file_saver6DialogC010openSaveAsC06params6resultyAA6ParamsV_yypSgctFySo15NSModalResponseacfU_ + 1138
9 file_saver 0x000000010619a2d0 $sSo15NSModalResponseaIegy_ABIeyBy_TR + 48
10 AppKit 0x00007ff811bd420e -[NSSavePanel didEndPanelWithReturnCode:] + 76
11 AppKit 0x00007ff811bd4460 -[NSSavePanel completeModeless:] + 23
12 AppKit 0x00007ff811bd4769 -[NSSavePanel completeWithReturnCode:url:urls:] + 449
13 AppKit 0x00007ff811bd679a -[NSSavePanel observeValueForKeyPath:ofObject:change:context:] + 325
14 Foundation 0x00007ff80f5c31aa NSKeyValueNotifyObserver + 306
15 Foundation 0x00007ff80f6870b9 NSKeyValueDidChange + 431
16 Foundation 0x00007ff80f72f84e NSKeyValueDidChangeWithPerThreadPendingNotifications + 146
17 ViewBridge 0x00007ff815cf6091 __41-[NSViewBridge setObject:forKey:withKVO:]_block_invoke + 360
18 ViewBridge 0x00007ff815d76701 withHintInProgress + 198
19 ViewBridge 0x00007ff815cedf77 -[NSViewBridge setObject:forKey:withKVO:] + 417
20 ViewBridge 0x00007ff815cef1cc -[NSViewBridge nonLocalChangeInProgress:block:] + 172
21 ViewBridge 0x00007ff815ceef8c -[NSRemoteViewMarshal exceptionSafeSetRemoteObject:forKey:withReply:] + 264
22 ViewBridge 0x00007ff815ceee42 -[NSRemoteViewMarshal setRemoteObject:forKey:withReply:] + 56
23 CoreFoundation 0x00007ff80e7709cc __invoking___ + 140
24 CoreFoundation 0x00007ff80e770873 -[NSInvocation invoke] + 305
25 ViewBridge 0x00007ff815cecf00 __deferNSXPCInvocationOntoMainThread_block_invoke + 228
26 ViewBridge 0x00007ff815ce02c4 __wrapBlockWithVoucher_block_invoke + 37
27 ViewBridge 0x00007ff815cdff4f __deferBlockOntoMainThread_block_invoke_2 + 274
28 CoreFoundation 0x00007ff80e78cd31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
29 CoreFoundation 0x00007ff80e78cbdc __CFRunLoopDoBlocks + 445
30 CoreFoundation 0x00007ff80e78bf4d __CFRunLoopRun + 2609
31 CoreFoundation 0x00007ff80e78ae5c CFRunLoopRunSpecific + 562
32 HIToolbox 0x00007ff8174325e6 RunCurrentEventLoopInMode + 292
33 HIToolbox 0x00007ff81743234a ReceiveNextEventCommon + 594
34 HIToolbox 0x00007ff8174320e5 _BlockUntilNextEventMatchingListInModeWithFilter + 70
35 AppKit 0x00007ff8111ca1fd _DPSNextEvent + 927
36 AppKit 0x00007ff8111c88ba -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1394
37 AppKit 0x00007ff8113cc810 -[NSWindow(NSEventRouting) trackEventsMatchingMask:timeout:mode:handler:] + 261
38 ViewBridge 0x00007ff815d53e98 -[NSRemoteView _beginTrackingLoop:reply:] + 379
39 ViewBridge 0x00007ff815d56be4 -[NSRemoteViewMarshal beginTrackingLoop:reply:] + 48
40 CoreFoundation 0x00007ff80e7709cc __invoking___ + 140
41 CoreFoundation 0x00007ff80e770873 -[NSInvocation invoke] + 305
42 ViewBridge 0x00007ff815cecf00 __deferNSXPCInvocationOntoMainThread_block_invoke + 228
43 ViewBridge 0x00007ff815ce02c4 __wrapBlockWithVoucher_block_invoke + 37
44 ViewBridge 0x00007ff815cdff4f __deferBlockOntoMainThread_block_invoke_2 + 274
45 CoreFoundation 0x00007ff80e78cd31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
46 CoreFoundation 0x00007ff80e78cbdc __CFRunLoopDoBlocks + 445
47 CoreFoundation 0x00007ff80e78bf4d __CFRunLoopRun + 2609
48 CoreFoundation 0x00007ff80e78ae5c CFRunLoopRunSpecific + 562
49 HIToolbox 0x00007ff8174325e6 RunCurrentEventLoopInMode + 292
50 HIToolbox 0x00007ff81743234a ReceiveNextEventCommon + 594
51 HIToolbox 0x00007ff8174320e5 _BlockUntilNextEventMatchingListInModeWithFilter + 70
52 AppKit 0x00007ff8111ca1fd _DPSNextEvent + 927
53 AppKit 0x00007ff8111c88ba -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1394
54 AppKit 0x00007ff8111baf69 -[NSApplication run] + 586
55 AppKit 0x00007ff81118eee7 NSApplicationMain + 817
56 Cutting Board Builder 0x00000001060659e9 main + 9
57 dyld 0x000000010e03351e start + 462
)
Flutter Doctor:
cutting_board_maker % flutter -v doctor
[ā] Flutter (Channel stable, 3.0.0, on macOS 12.4 21F79 darwin-x64, locale en-US)
ā¢ Flutter version 3.0.0 at /Users/user/Development/Flutter/flutter
ā¢ Upstream repository https://github.com/flutter/flutter.git
ā¢ Framework revision ee4e09cce0 (3 weeks ago), 2022-05-09 16:45:18 -0700
ā¢ Engine revision d1b9a6938a
ā¢ Dart version 2.17.0
ā¢ DevTools version 2.12.2
[ā] Android toolchain - develop for Android devices
ā Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.
[ā] Xcode - develop for iOS and macOS (Xcode 13.4)
ā¢ Xcode at /Applications/Xcode.app/Contents/Developer
ā¢ CocoaPods version 1.11.2
[ā] Chrome - develop for the web
ā¢ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[!] Android Studio (not installed)
ā¢ Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
[ā] VS Code (version 1.67.2)
ā¢ VS Code at /Applications/Visual Studio Code.app/Contents
ā¢ Flutter extension version 3.42.0
[ā] Connected device (2 available)
ā¢ macOS (desktop) ā¢ macos ā¢ darwin-x64 ā¢ macOS 12.4 21F79 darwin-x64
ā¢ Chrome (web) ā¢ chrome ā¢ web-javascript ā¢ Google Chrome 102.0.5005.61
[ā] HTTP Host Availability
ā¢ All required HTTP hosts are available
! Doctor found issues in 2 categories.
cutting_board_maker %