flutter-plugins icon indicating copy to clipboard operation
flutter-plugins copied to clipboard

Black Screen when I open webview

Open EtcGonza opened this issue 2 years ago • 0 comments

Greetings! I'm trying to open a webpage with desktop_webview_window. But when I do it I get this error

Inspection is enabled by default for process or parent application with 'com.apple.security.get-task-allow' entitlement linked against old SDK. Use `inspectable` API to enable inspection on newer SDKs.

════════ 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>
binding.dart:497
#1      BindingBase.debugCheckZone
binding.dart:502
#2      runApp
binding.dart:1080
#3      runWebViewTitleBarWidget.<anonymous closure>
title_bar.dart:34
#8      runWebViewTitleBarWidget
title_bar.dart:31
#9      main
main.dart:7
#10     _runMain.<anonymous closure> (dart:ui/hooks.dart:129:23)
#11     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:296:19)
#12     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
(elided 4 frames from dart:async)
════════════════════════════════════════════════════════════════════════════════

If I try to open the webview again I get this error too

"load url: https://www.google.com/"
<desktop_webview_window.WebviewWindowController: 0x7f90a8b9a7d0> deinited
<desktop_webview_window.WebViewLayoutController: 0x7f90a88f6870> deinited
"load url: https://www.google.com/"
embedder.cc (2372): 'FlutterEngineSendPlatformMessage' returned 'kInvalidArguments'. Invalid engine handle.
2023-09-25 16:12:16.879 desktop_platform_ch[27921:355518] Failed to send message to Flutter engine on channel 'webview_message/client_channel' (2).
embedder.cc (2372): 'FlutterEngineSendPlatformMessage' returned 'kInvalidArguments'. Invalid engine handle.
2023-09-25 16:12:16.906 desktop_platform_ch[27921:355518] Failed to send message to Flutter engine on channel 'webview_message/client_channel' (2).

This is my code

import 'package:flutter/material.dart';
import 'package:desktop_webview_window/desktop_webview_window.dart';

void main(List<String> args) async {
  WidgetsFlutterBinding.ensureInitialized();

  if (runWebViewTitleBarWidget(args)) {
    return;
  }

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const WebView(),
    );
  }
}

class WebView extends StatefulWidget {
  const WebView({super.key});

  @override
  State<WebView> createState() => _WebViewState();
}

class _WebViewState extends State<WebView> {
  @override
  void initState() {
    super.initState();
    // web();
  }

  void web() async {
    final webview = await WebviewWindow.create(
      configuration: const CreateConfiguration(title: "WebViewExample"),
    );
    webview.launch("https://www.google.com/");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Test'),
      ),
      body: ElevatedButton(onPressed: web, child: Text('Open')),
    );
  }
}

Reproduce Steps

Steps to reproduce the behavior:

  1. Copy and paste my code
  2. Click on the 'Open' button
  3. Look the debug console

Expected behavior

I need that when I click on the 'Open' button a new windows open with the webview.

Version (please complete the following information):

  • Flutter Version: 3.10.1 • channel stable
  • OS: MacBook Pro
  • plugin: desktop_webview_window

EtcGonza avatar Sep 25 '23 19:09 EtcGonza