Flutter: Unable to initialize() in Chrome web application due to reliance on Platform._operatingSystem
Closed this issue · 1 comments
When calling initialize()
from a DockerCommander(DockerHostLocal())
object, I get an error when using Chrome.
This is not the case when using a Windows application.
I only bring this up because the package on pub.dev says that it is compatible with the web platform which is something that I would prefer to use in my use case. That is why I chose this package.
Let me know if there are any clarifications you need!
Replicate
- Put the example code into a Dart function anywhere (as long as you can call it). I called mine
startDockerDemo
. - Call the function via a Flutter widget
I used a text button to call the function, like so (note that cn is just a reference to the separate file where I have the function stored):
- Run using "Chrome (web-javascript)" device
- Observe error
- Run again using "Windows (windows-x64)" device
- Will run the demo as expected
Chrome (web-javascript) debug output (snippet - see full below)
Windows (windows-x64) debug output
Full debug output from Chrome (web-javascript)
Restarted application in 232ms.
Error: Unsupported operation: Platform._operatingSystem
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:49 throw_
dart-sdk/lib/_internal/js_dev_runtime/patch/io_patch.dart 244:5 _operatingSystem
dart-sdk/lib/io/platform_impl.dart 56:40 get operatingSystem
dart-sdk/lib/io/platform.dart 66:45 get _operatingSystem
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 941:8 get
dart-sdk/lib/io/platform.dart 152:51 get isWindows
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 941:8 get
packages/docker_commander/src/docker_commander_local.dart 84:18 resolveDockerBinaryPath
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async
packages/docker_commander/src/docker_commander_local.dart 82:48 resolveDockerBinaryPath
packages/docker_commander/src/docker_commander_local.dart 61:51 initialize
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async
packages/docker_commander/src/docker_commander_local.dart 54:26 initialize
packages/docker_commander/src/docker_commander_base.dart 28:58 initialize
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async
packages/docker_commander/src/docker_commander_base.dart 24:26 initialize
packages/physbox/control_node.dart 15:25 startDockerDemo
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async
packages/physbox/control_node.dart 14:16 startDockerDemo
packages/physbox/screens/networks_screen.dart 43:20 <fn>
packages/flutter/src/material/ink_well.dart 1154:21 handleTap
packages/flutter/src/gestures/recognizer.dart 275:24 invokeCallback
packages/flutter/src/gestures/tap.dart 654:11 handleTapUp
packages/flutter/src/gestures/tap.dart 311:5 [_checkUp]
packages/flutter/src/gestures/tap.dart 244:7 handlePrimaryPointer
packages/flutter/src/gestures/recognizer.dart 630:9 handleEvent
packages/flutter/src/gestures/pointer_router.dart 98:12 [_dispatch]
packages/flutter/src/gestures/pointer_router.dart 143:9 <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 21:13 forEach
packages/flutter/src/gestures/pointer_router.dart 141:17 [_dispatchEventToRoutes]
packages/flutter/src/gestures/pointer_router.dart 127:7 route
packages/flutter/src/gestures/binding.dart 465:19 handleEvent
packages/flutter/src/gestures/binding.dart 445:14 dispatchEvent
packages/flutter/src/rendering/binding.dart 331:11 dispatchEvent
packages/flutter/src/gestures/binding.dart 400:7 [_handlePointerEventImmediately]
packages/flutter/src/gestures/binding.dart 363:5 handlePointerEvent
packages/flutter/src/gestures/binding.dart 320:7 [_flushPointerEventQueue]
packages/flutter/src/gestures/binding.dart 293:9 [_handlePointerDataPacket]
lib/_engine/engine/platform_dispatcher.dart 1251:13 invoke1
lib/_engine/engine/platform_dispatcher.dart 269:5 invokeOnPointerDataPacket
lib/_engine/engine/pointer_binding.dart 168:39 [_onPointerData]
lib/_engine/engine/pointer_binding.dart 791:20 <fn>
lib/_engine/engine/pointer_binding.dart 720:14 <fn>
lib/_engine/engine/pointer_binding.dart 317:16 loggedHandler
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 367:37 _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 372:39 dcall
When running inside Flutter for Web, you should only import 'package:docker_commander/docker_commander.dart';
(and not the _vm
file).
Next, you will need to use the remote version:
var dockerCommander = DockerCommander(DockerHostRemote(host, port, username: '...', password: '...'));
Additionally, you will require a DockerCommander
server.
Please refer to the example below for the client and server example:
https://github.com/gmpassos/docker_commander#remote-docker