我试图使用(canGoBack())方法与(flutter webview加)插件,但它不工作!!
vs代码表示:
没有为类型“WebViewPlusController”定义方法“canGoBack”。请尝试将名称更正为现有方法的名称,或定义名为“canGoBack”的方法。
这是我代码:
//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;
},
),
),
),
),
);
}
我怎样才能解决这个问题?
我试图使用(canGoBack())方法与(flutter webview加)插件,但它不工作!!
1条答案
按热度按时间cwtwac6a1#
要使用方法
canGoBack
,您必须访问WebViewPlusController的属性webViewController,下面是一个示例:更多信息,请访问:https://pub.dev/documentation/webview_flutter_plus/latest/webview_flutter_plus/WebViewPlusController-class.html