简体   繁体   English

未为 flutter WebViewPlus 定义“canGoBack”方法

[英]'canGoBack' method isn't defined for flutter WebViewPlus

I'm trying to use ( canGoBack() ) method with (flutter webview plus) plugin but it isn't work!!我正在尝试将 (canGoBack()) 方法与 (flutter webview plus) 插件一起使用,但它不起作用!!

vs code said: vs代码说:

The method 'canGoBack' isn't defined for the type 'WebViewPlusController'.方法“canGoBack”没有为类型“WebViewPlusController”定义。 Try correcting the name to the name of an existing method, or defining a method named 'canGoBack'.尝试将名称更正为现有方法的名称,或定义名为“canGoBack”的方法。

this is my code:这是我的代码:

//import 'dart:async';
import 'package:flutter/material.dart';
import 'package:webview_flutter_plus/webview_flutter_plus.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  late WebViewPlusController controller;
  @override
  Widget build(BuildContext context)  => WillPopScope (
    onWillPop: () async {
      if (await controller.canGoBack() ) {
      return false; }
    },
    child: SafeArea(
      child: Scaffold(
        // ignore: avoid_unnecessary_containers
        body: Container(
          child: WebViewPlus(
            initialUrl: 'assets/index.html',
            javascriptMode: JavascriptMode.unrestricted,
            onWebViewCreated: (controller) {
              this.controller = controller;
              },
            ),
          ),
        ),
      ),
    );
  }

how can I solve this problem?我怎么解决这个问题?

I'm trying to use ( canGoBack() ) method with (flutter webview plus) plugin but it isn't work!!我正在尝试将 (canGoBack()) 方法与 (flutter webview plus) 插件一起使用,但它不起作用!!

To use the method canGoBack you have to access the WebViewPlusController's property webViewController, here an example:要使用canGoBack方法,您必须访问 WebViewPlusController 的属性 webViewController,这里是一个示例:

if (await controller.webViewController.canGoBack()) {
    return false;
}

More information in: https://pub.dev/documentation/webview_flutter_plus/latest/webview_flutter_plus/WebViewPlusController-class.html更多信息见: https://pub.dev/documentation/webview_flutter_plus/latest/webview_flutter_plus/WebViewPlusController-class.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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