WidgetFactory extension to render IFRAME with the official WebView plugin. This is a companion add-on for flutter_widget_from_html_core package.
Live demo: https://demo.fwfh.dev/#/iframe
Add this to your app's pubspec.yaml
file:
dependencies:
flutter_widget_from_html_core: any
fwfh_webview: ^0.14.2
Then use HtmlWidget
with a custom factory:
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:fwfh_webview/fwfh_webview.dart';
// ...
HtmlWidget(
html,
factoryBuilder: () => MyWidgetFactory(),
)
// ...
class MyWidgetFactory extends WidgetFactory with WebViewFactory {
// optional: override getter to configure how WebViews are built
bool get webViewMediaPlaybackAlwaysAllow => true;
String? get webViewUserAgent => 'My app';
}
Configurable getters:
Type | Default | |
---|---|---|
webView | bool | true |
webViewDebuggingEnabled | bool | false |
webViewJs | bool | true |
webViewMediaPlaybackAlwaysAllow | bool | false |
webViewOnAndroidHideCustomWidget | Function | null |
webViewOnAndroidShowCustomWidget | Function | null |
webViewUserAgent | String | null |
Supported IFRAME attributes:
Run this command:
With Flutter:
$ flutter pub add fwfh_webview
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get
):
dependencies:
fwfh_webview: ^0.14.2
Alternatively, your editor might support flutter pub get
. Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:fwfh_webview/fwfh_webview.dart';
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:fwfh_webview/fwfh_webview.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'fwfh_webview',
home: Scaffold(
appBar: AppBar(
title: const Text('WebViewFactory Demo'),
),
body: Center(
child: HtmlWidget(
'<iframe src="https://www.youtube.com/embed/jNQXAC9IVRw"></iframe>',
factoryBuilder: () => MyWidgetFactory(),
),
),
),
);
}
}
class MyWidgetFactory extends WidgetFactory with WebViewFactory {}
Download details:
Author: daohoangson.com
Source: https://github.com/daohoangson/flutter_widget_from_html