iFrame for Flutter Web,iOS & Android应用程序

toiithl6  于 2023-05-29  发布在  Flutter
关注(0)|答案(1)|浏览(202)

我想为我的Flutter Web、Android和IOS应用程序集成一些来自多个来源(不仅是YouTube)的iFrames,但我没有成功。
我在www.example.com上搜索pub.dev是否有一个软件包可以用于3个平台,我没有找到它。所以我使用Android和iOS的WebView,但我不知道该怎么做的Web。我尝试使用“IFrameElement类”,但没有成功...(我不是很好……)
1.你知道我能用的神奇套餐吗?
1.否则,你推荐什么(多个包,只有WebView和IFrameElement,其他的...)?
1.你能帮我写下面的代码吗?

import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:webview_flutter/webview_flutter.dart';

class ShowIframe extends StatefulWidget {
  const ShowIframe({
    Key? key,
    required this.link,
  }) : super(key: key);

  final String link;

  @override
  State<ShowIframe> createState() => _ShowIframeState();
}

class _ShowIframeState extends State<ShowIframe> {
  @override
  Widget build(BuildContext context) {
    if (kIsWeb) {
      return Scaffold(
        appBar: AppBar(
          title: const Text('Iframe on Flutter Web'),
        ),
        body: , // I don't know
      );
    } else {
      return Scaffold(
        appBar: AppBar(
          title: const Text('Iframe on Flutter Android & IOS'),
        ),
        body: WebView(
          initialUrl: widget.link,
          javascriptMode: JavascriptMode.unrestricted,
        ),
      );
    }
  }
}

对于“链接”,如果我有这个iFrame:

<iframe width="560" height="315" src="https://www.youtube.com/embed/yRlwOdCK7Ho" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

我使用“https://www.youtube.com/embed/yRlwOdCK7Ho”
也许有另一种方法来使用整个iFrame代码...
提前感谢!

py49o6xq

py49o6xq1#

对于flutter中的iframe,我们使用这个包https://pub.dev/packages/flutter_inappwebview,它工作得最稳定,注入javascript通常很容易。我可以提供一些代码,如果需要的话

相关问题