Does this package work on Flutter Web
tomrobinsonv opened this issue · 1 comments
Hi, we're trying to implement GCloud Pubsub on Web but running into an issue on initialisation where it is trying to find the Platform._environment which is unsupported on Web. Just wanted some clarification on this as I can't find much information on this anywhere.
Dart Version: 2.18.6
Flutter Version: 3.3.10
GCloud Version: ^0.8.7
Google APIS Auth: ^1.3.1
This is the error I get when trying to create PubSub Instance.
Error: Unsupported operation: Platform._environment
dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49 throw
dart-sdk/lib/_internal/js_dev_runtime/patch/io_patch.dart 284:5 _environment
dart-sdk/lib/io/platform_impl.dart 83:17 get environment
dart-sdk/lib/io/platform.dart 168:59 get environment
packages/gcloud/pubsub.dart 129:40 new
packages/test_device_management/src/engine/dependencies/app_dependencies.dart 56:29 _setupServices
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50
dart-sdk/lib/async/zone.dart 1653:54 runUnary
dart-sdk/lib/async/future_impl.dart 147:18 handleValue
dart-sdk/lib/async/future_impl.dart 766:44 handleValueCallback
dart-sdk/lib/async/future_impl.dart 795:13 _propagateToListeners
dart-sdk/lib/async/future_impl.dart 566:5 [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 639:7 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15
I have managed to get this working by manually going into the pubsub.dart file and removing the Platform.environment check which was causing the issue. It seems like this is all that's blocking it on web and it's only there check wether it is running on an emulator or not. Is it possible to get this removed or just add a check like
{ if(kIsWeb) check emulator }
, so it can work on web.
This is the code I changed.
factory PubSub(http.Client client, String project) { var emulator = Platform.environment['PUBSUB_EMULATOR_HOST']; return emulator == null ? _PubSubImpl(client, project) : _PubSubImpl.rootUrl(client, project, 'http://$emulator/'); }
to this
factory PubSub(http.Client client, String project) { return _PubSubImpl(client, project); }