Flutter WebView:如何在 WebView 内容中实现谷歌翻译?

3

我想使用谷歌翻译工具自动翻译 Webview 的内容,在 Flutter 中没有找到任何相关信息。我只想在导航栏的弹出菜单按钮中显示一个类型为“翻译此页面”的选项。感谢您的指导。

这是我目前的代码:

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: Text(nameCourse.toString()),
          centerTitle: true,
          actions: <Widget>[
            PopupMenuButton<String>(
              onSelected: handleClick,
              itemBuilder: (BuildContext context) {
                return {
                  'Translate this page',
                  'Compartir mediante...',
                  'Abrir en Chrome',
                  'Copiar Enlace'
                }.map((String choice) {
                  return PopupMenuItem<String>(
                    value: choice,
                    child: Text(choice),
                  );
                }).toList();
              },
            ),
          ]),
      body: WebView(
        userAgent: "random",
        javascriptMode: JavascriptMode.unrestricted,
        initialUrl: urlCourse.toString(),
      ),
    );
  }

  void handleClick(String value) {
    switch (value) {
      case 'Copiar Enlace':
        copiarEnlace();
        break;
      case 'Translate thi page':
        //translate()
        break;
      case 'Abrir en Chrome':
        openUrl();
        break;
      case 'Compartir mediante...':
        compartirUrl();
        break;
    }
  }

你找到解决这个问题的方法了吗? - Nazmul Hasan
暂时不行,至少用Flutter目前还不可能。 - Carlos Peñaranda
好的,谢谢。但如果你找到任何解决方案,请在这里更新。 - Nazmul Hasan
@CarlosPeñaranda,你解决问题了吗?如果是,请留下你的答案。 - Rustam-Z
1个回答

0

我找不到翻译选项。 - Rustam-Z
这个选项是在编译应用程序后出现在Chrome应用内浏览器选项中的。它不是方法。 - Scorpion

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接