WidgetFactory Extension To Render IFRAME with The Official WebView Plugin For Flutter

WebViewFactory 

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

Getting Started 

Add this to your app's pubspec.yaml file:

dependencies:
  flutter_widget_from_html_core: any
  fwfh_webview: ^0.14.2

Usage 

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';
}

Features 

Configurable getters:

 TypeDefault
webViewbooltrue
webViewDebuggingEnabledboolfalse
webViewJsbooltrue
webViewMediaPlaybackAlwaysAllowboolfalse
webViewOnAndroidHideCustomWidgetFunctionnull
webViewOnAndroidShowCustomWidgetFunctionnull
webViewUserAgentStringnull

Supported IFRAME attributes:

  • src
  • width, height
  • sandbox
    • allow-scripts

Use this package as a library

Depend on it

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.

Import it

Now in your Dart code, you can use:

import 'package:fwfh_webview/fwfh_webview.dart';

example/main.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

#flutter #android #ios

WidgetFactory Extension To Render IFRAME with The Official WebView Plugin For Flutter
1.90 GEEK