后退按钮不会返回页面,而是退出 FLUTTER 中的 webview

问题描述 投票:0回答:1

当我单击后退按钮时,如何做到这一点不关闭网页视图,而是从网页视图第一步返回

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,
      ),
    );
  }
}

我想知道如何解决这个问题

flutter webview flutter-dependencies
1个回答
0
投票
bool _isLoading = true;

appBar: AppBar(
        title: Text('WebView'),
        leading: IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: () {
            if (_controller != null) {
              _controller.goBack();
            }
          },
        ),
      ),
© www.soinside.com 2019 - 2024. All rights reserved.