我是在旅途中学习颤振的新手,当没有更多的 WebView 返回历史记录时,我正在尝试使用返回按钮关闭我的应用程序。例如,在 WebView 应用程序中,初始 URL 是 google.com,我导航到 yahoo.com,当我按下后退按钮时,它会返回 google.com,如果我再次按下应用程序什么也不做,我希望它在没有时退出更多的历史。我在 Flutter WebView 插件页面上尝试了 CanGoBack() 函数,但在 vscode 中出现错误。我不知道如何实现。
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
class WebviewInFlutter extends StatefulWidget {
WebviewInFlutter({Key key}) : super(key: key);
@override
_WebviewInFlutterState createState() => _WebviewInFlutterState();
}
class _WebviewInFlutterState extends State<WebviewInFlutter> {
final FirebaseMessaging _messaging = FirebaseMessaging();
@override
void initState(){
super.initState();
_messaging.getToken().then((token) {
print(token);
});
_messaging.configure(
onMessage: (Map<String, dynamic> message) async{
print('on message $message');
},
onResume: (Map<String, dynamic> message) async{
print('on resume $message');
},
onLaunch: (Map<String, dynamic> message) async{
print('on launch $message');
},
);
_messaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
}
final flutterWebviewPlugin = new FlutterWebviewPlugin();
@override
Widget build(BuildContext context) {
return WebviewScaffold(
url: 'https://google.com',
hidden: true,
appCacheEnabled: true,
withJavascript: true,
withLocalStorage: true,
appBar: AppBar(
actions: <Widget>[
IconButton(
icon: Icon(Icons.refresh, color: Color.fromRGBO(255, 255, 255, 1.0),),
onPressed: () => flutterWebviewPlugin.reload(), // this is reloading the url that was provided to webview, not the current URL.
)
],
elevation: 1.0,
centerTitle: true,
title: Text("Google Mobile")
),
);
}
}