Agora-Flutter-SDK icon indicating copy to clipboard operation
Agora-Flutter-SDK copied to clipboard

Initialization on web does not seem to await

Open duck-dev-go opened this issue 3 years ago • 3 comments

Describe the bug I get the following bug when creating the engine in my main function for flutter web

errors.dart:251 Uncaught (in promise) Error: PlatformException(error, LateInitializationError: Field '_engineMain' has not been initialized., null, null)
    at Object.throw_ [as throw] (errors.dart:251:49)
    at StandardMethodCodec.decodeEnvelope (message_codecs.dart:607:7)
    at MethodChannel._invokeMethod (platform_channel.dart:167:18)
    at _invokeMethod.next (<anonymous>)
    at async_patch.dart:45:50
    at _RootZone.runUnary (zone.dart:1685:54)
    at _FutureListener.thenAwait.handleValue (future_impl.dart:147:18)
    at handleValueCallback (future_impl.dart:766:44)
    at _Future._propagateToListeners (future_impl.dart:795:13)
    at [_completeWithValue] (future_impl.dart:566:5)
    at async._AsyncCallbackEntry.new.callback (future_impl.dart:639:7)
    at Object._microtaskLoop (schedule_microtask.dart:40:11)
    at _startMicrotaskLoop (schedule_microtask.dart:49:5)
    at async_patch.dart:166:15

To Reproduce Put this in you main function and run on flutter web

 final agoraEngine = await RtcEngine.create(
    AgoraEnvironment.appId,
  );

but if you put this in you main function

  await Future.delayed(Duration(milliseconds: 1000));

  final agoraEngine = await RtcEngine.create(
    AgoraEnvironment.appId,
  );

it does work. But this is unreliable. The creation should be awaited.

Expected behavior The intialization of the engine to be awaited

Desktop (please complete the following information): Latest version of chrome Macbook pro m1 Flutter: 3.0.1 Package Agora: 5.2.0

duck-dev-go avatar Jun 27 '22 15:06 duck-dev-go

I don't think you can call it in the main function directly, the _engineMain will be initialized after the js script is loaded. https://github.com/AgoraIO/Agora-Flutter-SDK/blob/28d8848a084c2f9755841ef6a5627df97a10598e/lib/agora_rtc_engine_web.dart#L104

littleGnAl avatar Jun 30 '22 13:06 littleGnAl

I can also not call it on the splash screen in a initState() I will get the same error. It will only work with a 1 second delay.

duck-dev-go avatar Jun 30 '22 13:06 duck-dev-go

This problem occurs even with the example code provided in pub.dev

OutdatedGuy avatar Aug 01 '22 10:08 OutdatedGuy

The web support for agora_rtc_engine 6.x has landed in the main branch, If you still face issues, please try the latest code in main branch to see if it works or not.

littleGnAl avatar Nov 14 '23 08:11 littleGnAl

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. If you find this problem please file a new issue with the same description, what happens, logs and the output. All system setups can be slightly different so it's always better to open new issues and reference the related ones. Thanks for your contribution.

github-actions[bot] avatar Nov 28 '23 09:11 github-actions[bot]

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please raise a new issue.

github-actions[bot] avatar Dec 05 '23 10:12 github-actions[bot]