Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zone mismatch. desktop_webview_window 0.2.3 #327

Open
huangsir0 opened this issue Apr 18, 2024 · 1 comment
Open

Zone mismatch. desktop_webview_window 0.2.3 #327

huangsir0 opened this issue Apr 18, 2024 · 1 comment

Comments

@huangsir0
Copy link

A clear and concise description of what the bug is.

Reproduce Steps

 if (runWebViewTitleBarWidget(args)) {
    return;
  }

Error log

════════ Exception caught by Flutter framework ═════════════════════════════════
The following assertion was thrown during runApp:
Zone mismatch.
The Flutter bindings were initialized in a different zone than is now being used. This will likely cause confusion and bugs as any zone-specific configuration will inconsistently use the configuration of the original binding initialization zone or this zone based on hard-to-predict factors such as which zone was active when a particular callback was set.
It is important to use the same zone when calling `ensureInitialized` on the binding as when calling `runApp` later.
To make this warning fatal, set BindingBase.debugZoneErrorsAreFatal to true before the bindings are initialized (i.e. as the first statement in `void main() { }`).

When the exception was thrown, this was the stack:
#0      BindingBase.debugCheckZone.<anonymous closure> (package:flutter/src/foundation/binding.dart:495:29)
binding.dart:495
#1      BindingBase.debugCheckZone (package:flutter/src/foundation/binding.dart:500:6)
binding.dart:500
#2      runApp (package:flutter/src/widgets/binding.dart:1212:18)
binding.dart:1212
#3      runWebViewTitleBarWidget.<anonymous closure> (package:desktop_webview_window/src/title_bar.dart:34:7)
title_bar.dart:34
#8      runWebViewTitleBarWidget (package:desktop_webview_window/src/title_bar.dart:31:3)
title_bar.dart:31
#9      main (package:walang/main.dart:19:7)
main.dart:19
#10     _runMain.<anonymous closure> (dart:ui/hooks.dart:299:23)
hooks.dart:299
#11     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
isolate_patch.dart:297
#12     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
isolate_patch.dart:184
(elided 4 frames from dart:async)
════════════════════════════════════════════════════════════════════════════════
../../flutter/shell/platform/embedder/embedder.cc (2472): 'FlutterEngineSendPlatformMessage' returned 'kInvalidArguments'. Invalid engine handle.

**Version

  • Flutter Version: 3.19.4
  • OS: Windows
  • plugin: desktop_webview_window 0.2.3
@LightningDev1
Copy link

I fixed this by moving WidgetsFlutterBinding.ensureInitialized() to after the runWebViewTitleBarWidget check.

The reason this happens is because runWebViewTitleBarWidget run the titlebar widget in a guarded zone, which will be different than the one the widget binding is initialized in, if you initialize it before running the titlebar widget.

bool runWebViewTitleBarWidget(
  List<String> args, {
  WidgetBuilder? builder,
  Color? backgroundColor,
  void Function(Object error, StackTrace stack)? onError,
}) {
  // ...
  runZonedGuarded( // <-- this is what causes the problem
    () {
      WidgetsFlutterBinding.ensureInitialized();
      runApp(_TitleBarApp(
        // ...
      ));
    },
    onError ??
        (e, s) {
          debugPrint('WebViewTitleBar: unhandled expections: $e, $s');
        },
  );

  return true;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants