当我单击后退按钮时,如何做到这一点不关闭网页视图,而是从网页视图第一步返回
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class WebView extends StatefulWidget {
const WebView({super.key});
@override
State<WebView> createState() => _WebViewState();
}
class _WebViewState extends State<WebView> {
final controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..loadRequest(Uri.parse("https://youtube.com/"));
//
@override
Widget build(BuildContext context) {
return SafeArea(
child: WebViewWidget(
controller: controller,
),
);
}
}
我想知道如何解决这个问题
bool _isLoading = true;
appBar: AppBar(
title: Text('WebView'),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
if (_controller != null) {
_controller.goBack();
}
},
),
),