我使用webview_flutter来显示网络视图。现在,我想在Web视图中选择一些文本,并显示一个弹出操作菜单(类似于iOS中的UIMenuController),以对文本进行一些自定义操作,例如将其翻译为另一种语言或将其标记为以后阅读,那么如何我收到所选的文字了吗?
我搜索了Google和Flutter github问题,关键词为'flutter webview text select','flutter webview text edit','flutter webview uimenucontroller'等,但是我发现没有任何用处。
我用来显示网络视图的代码如下:
class SessionDetailPage extends StatefulWidget {
final Session session;
SessionDetailPage({Key key, @required this.session}) : super(key: key);
@override
_SessionDetailState createState() => new _SessionDetailState();
}
class _SessionDetailState extends State<SessionDetailPage> {
final Completer<WebViewController> _controller = Completer<WebViewController>();
Future<bool> _requestPop() {
Navigator.of(context).pop(widget.session);
return Future.value(false);
}
@override
Widget build(BuildContext context) {
return WillPopScope(
child: Scaffold(
appBar: AppBar(
title: Text(
widget.session.sessionTitle,
),
),
body: Builder(builder: (BuildContext context) {
return WebView(
initialUrl: widget.session.sessionUrlString,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
onPageFinished: (String url) {
},
);
}),
),
onWillPop: _requestPop,
);
}
}