incrediblezayed / file_saver

A simple flutter plugin for saving files in all platforms
https://pub.dev/packages/file_saver
BSD 3-Clause "New" or "Revised" License
75 stars 103 forks source link

DartError: Unsupported operation: Platform._operatingSystem #125

Closed frozenfangkb closed 1 month ago

frozenfangkb commented 1 month ago

While trying to use this plugin with Flutter web, I get this error and I'm unable to download the file.

Log:

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                runBody
async_patch.dart:84

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5                _async
async_patch.dart:127

packages/file_saver/src/utils/helpers.dart 69:38                                  getDirectory
helpers.dart:69

packages/file_saver/file_saver.dart 111:50                                        saveFileOnly
file_saver.dart:111

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                runBody
async_patch.dart:84

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5                _async
async_patch.dart:127

packages/file_saver/file_saver.dart 104:31                                        saveFileOnly
file_saver.dart:104

packages/file_saver/file_saver.dart 81:27                                         saveFile
file_saver.dart:81

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                runBody
async_patch.dart:84

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5                _async
async_patch.dart:127

packages/file_saver/file_saver.dart 51:26                                         saveFile
file_saver.dart:51

packages/trip_library/shared/widgets/trip_image.dart 52:20                        <fn>
trip_image.dart:52

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                runBody
async_patch.dart:84

dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5                _async
async_patch.dart:127

packages/trip_library/shared/widgets/trip_image.dart 50:24                        <fn>
trip_image.dart:50

packages/flutter/src/material/ink_well.dart 1170:21                               handleTap
ink_well.dart:1170

packages/flutter/src/gestures/recognizer.dart 351:24                              invokeCallback
recognizer.dart:351

packages/flutter/src/gestures/tap.dart 656:11                                     handleTapUp
tap.dart:656

packages/flutter/src/gestures/tap.dart 313:5                                      [_checkUp]
tap.dart:313

packages/flutter/src/gestures/tap.dart 283:7                                      acceptGesture
tap.dart:283

packages/flutter/src/gestures/arena.dart 169:12                                   sweep
arena.dart:169

packages/flutter/src/gestures/binding.dart 505:7                                  handleEvent
binding.dart:505

packages/flutter/src/gestures/binding.dart 481:14                                 dispatchEvent
binding.dart:481

packages/flutter/src/rendering/binding.dart 450:11                                dispatchEvent
binding.dart:450

packages/flutter/src/gestures/binding.dart 426:7                                  [_handlePointerEventImmediately]
binding.dart:426

packages/flutter/src/gestures/binding.dart 389:5                                  handlePointerEvent
binding.dart:389

packages/flutter/src/gestures/binding.dart 336:7                                  [_flushPointerEventQueue]
binding.dart:336

packages/flutter/src/gestures/binding.dart 305:9                                  [_handlePointerDataPacket]
binding.dart:305

lib/_engine/engine/platform_dispatcher.dart 1423:5                                invoke1
platform_dispatcher.dart:1423

lib/_engine/engine/platform_dispatcher.dart 336:5                                 invokeOnPointerDataPacket
platform_dispatcher.dart:336

lib/_engine/engine/pointer_binding.dart 405:30                                    [_sendToFramework]
pointer_binding.dart:405

lib/_engine/engine/pointer_binding.dart 225:7                                     onPointerData
pointer_binding.dart:225

lib/_engine/engine/pointer_binding.dart 1035:20                                   <fn>
pointer_binding.dart:1035

lib/_engine/engine/pointer_binding.dart 948:7                                     <fn>
pointer_binding.dart:948

lib/_engine/engine/pointer_binding.dart 541:9                                     loggedHandler
pointer_binding.dart:541

dart-sdk/lib/_internal/js_dev_runtime/patch/js_allow_interop_patch.dart 188:27    _callDartFunctionFast1
js_allow_interop_patch.dart:188

Implementation:

onPressed: () async {
              await FileSaver.instance
                  .saveFile(name: name, filePath: path, mimeType: mimeType);
            },

Versions:

file_saver: ^0.2.14
Flutter 3.24.3
Dart 3.5.3 • DevTools 2.37.3

Thanks, reach me out if I can help somehow :)

incrediblezayed commented 1 month ago

Hey @frozenfangkb can you give me insight on what kind of file you were trying to save?

frozenfangkb commented 1 month ago

Hello!

My bad, I was populating the filePath field with the URL of the photo which is hosted in a S3 bucket, so it was trying to use dart:io which doesn't work in Flutter web.

Thank you, I'm sorry ^^'