简体   繁体   中英

I have a question about using Webview in flutter

Hello I am having a problem while linking webview in flutter, so I want to ask a question.

First of all, webview is connected normally. However, when I click another hyperlink in the webview, the app itself is terminated.

In this case, is there anything else I need to deal with?

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

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  WebViewController _controller;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: WebView(
          initialUrl: 'https://www.notion.so/noteasy/915417f1fd964d1f92ad3bb6429b908a',
          javascriptMode: JavascriptMode.unrestricted,
        ),
      ),
    );
  }
}

This is the log that occurs when I press a hyperlink and it is forcibly terminated.

D/EGL_emulation(28572): eglMakeCurrent: 0xeaff8800: ver 2 0 (tinfo 0xdfa52190)
D/eglCodecCommon(28572): setVertexArrayObject: set vao to 0 (0) 1 2
W/TextClassifierService(28572): Package or service not found in package com.google.android.as for user 0
E/InputMethodManager(28572): b/117267690: Failed to get fallback IMM with expected displayId=14 actual IMM#displayId=0 view=io.flutter.plugins.webviewflutter.InputAwareWebView{2e377eb VFEDHVC.. .F...... 0,0-1080,1731}
D/eglCodecCommon(28572): setVertexArrayObject: set vao to 2 (2) 0 0
D/AndroidRuntime(28572): Shutting down VM
E/AndroidRuntime(28572): FATAL EXCEPTION: main
E/AndroidRuntime(28572): Process: kr.noteasy.sheeps_app, PID: 28572
E/AndroidRuntime(28572): java.lang.NullPointerException: Attempt to read from field 'android.view.WindowManager$LayoutParams android.view.ViewRootImpl.mWindowAttributes' on a null object reference
E/AndroidRuntime(28572):    at android.view.inputmethod.InputMethodManager.startInputInner(InputMethodManager.java:1625)
E/AndroidRuntime(28572):    at android.view.inputmethod.InputMethodManager.checkFocus(InputMethodManager.java:1864)
E/AndroidRuntime(28572):    at android.view.inputmethod.InputMethodManager.isActive(InputMethodManager.java:1183)
E/AndroidRuntime(28572):    at io.flutter.plugins.webviewflutter.InputAwareWebView$1.run(InputAwareWebView.java:188)
E/AndroidRuntime(28572):    at android.os.Handler.handleCallback(Handler.java:883)
E/AndroidRuntime(28572):    at android.os.Handler.dispatchMessage(Handler.java:100)
E/AndroidRuntime(28572):    at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(28572):    at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime(28572):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(28572):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime(28572):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process (28572): Sending signal. PID: 28572 SIG: 9

Upgrade to the latest stable and try again with the latest webview_flutter 0.3.22+1 . It fixed the issue in my case.

Add your SurfaceAndroidWebview for your Android Platform.

 @override
  void initState() {
    super.initState();
    if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM