我希望能有一个全屏的webview(下方没有tabbar,最上方是左边返回按钮中间是title)打开,点击返回按钮就直接返回到首页
时间: 2024-05-05 16:17:31 浏览: 14
您可以使用以下代码实现全屏的Webview并在左上角添加返回按钮:
```
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class FullScreenWebView extends StatelessWidget {
final String url;
final String title;
FullScreenWebView({required this.url, required this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Container(
height: MediaQuery.of(context).padding.top + kToolbarHeight,
color: Colors.white,
child: Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context).padding.top,
left: 16.0,
right: 16.0,
),
child: Row(
children: [
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Icon(Icons.arrow_back),
),
SizedBox(width: 16.0),
Expanded(
child: Text(
title,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
),
],
),
),
),
Expanded(
child: WebView(
initialUrl: url,
javascriptMode: JavascriptMode.unrestricted,
),
),
],
),
);
}
}
```
然后在需要使用的地方调用:
```
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FullScreenWebView(
url: 'https://www.example.com',
title: 'Example',
),
),
);
```
这样就可以实现全屏的Webview并在左上角添加返回按钮了。点击返回按钮即可返回到上一页。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)