From 403a644a98de25555f4f3f6050e76ef07c66ea2b Mon Sep 17 00:00:00 2001 From: Mark Fransen Date: Wed, 9 Aug 2023 16:10:14 -0700 Subject: [PATCH 1/4] Add srcdoc check when building IframeWidget This branch allows developers to, in addition to 'src', pass in html that contains a 'srcdoc' property. 'src' is great for passing in a URL, but if someone wants to pass in HTML, etc., inside an iframe, then we need to use 'srcdoc'. This branch is broken into three commits since there are three separate features being introduced. Check is 'srcdoc' is sent in with the extensionContext attributes. If there is no 'srcdoc' we fallback to 'src'. This change doesn't break the current usage of the package and will not impact developers currently using it. --- .../lib/iframe_mobile.dart | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/flutter_html_iframe/lib/iframe_mobile.dart b/packages/flutter_html_iframe/lib/iframe_mobile.dart index 9c73e65cba..7ef80489b0 100644 --- a/packages/flutter_html_iframe/lib/iframe_mobile.dart +++ b/packages/flutter_html_iframe/lib/iframe_mobile.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; @@ -34,6 +36,18 @@ class IframeWidget extends StatelessWidget { final givenHeight = double.tryParse(extensionContext.attributes['height'] ?? ""); + Uri? srcUri; + + if (extensionContext.attributes['srcdoc'] != null) { + srcUri = Uri.dataFromString( + extensionContext.attributes['srcdoc'] ?? '', + mimeType: 'text/html', + encoding: Encoding.getByName('utf-8'), + ); + } else { + srcUri = Uri.tryParse(extensionContext.attributes['src'] ?? "") ?? Uri(); + } + return SizedBox( width: givenWidth ?? (givenHeight ?? 150) * 2, height: givenHeight ?? (givenWidth ?? 300) / 2, @@ -41,10 +55,7 @@ class IframeWidget extends StatelessWidget { style: extensionContext.styledElement!.style, childIsReplaced: true, child: WebViewWidget( - controller: controller - ..loadRequest( - Uri.tryParse(extensionContext.attributes['src'] ?? "") ?? - Uri()), + controller: controller..loadRequest(srcUri), key: key, gestureRecognizers: {Factory(() => VerticalDragGestureRecognizer())}, ), From e2a1c5210509bfccb7629472a2c6c15a0a0ab299 Mon Sep 17 00:00:00 2001 From: Mark Fransen Date: Wed, 9 Aug 2023 16:38:24 -0700 Subject: [PATCH 2/4] Update flutter_html internal package to point to this git repo We have to point them all to this repo otherwise pub get fails when trying to only point the flutter_html and flutter_html_iframe packages to this repo. They all need to be unified. --- packages/flutter_html_all/pubspec.yaml | 37 ++++++++++++++++++----- packages/flutter_html_audio/pubspec.yaml | 7 +++-- packages/flutter_html_iframe/pubspec.yaml | 7 +++-- packages/flutter_html_math/pubspec.yaml | 6 +++- packages/flutter_html_svg/pubspec.yaml | 6 +++- packages/flutter_html_table/pubspec.yaml | 6 +++- packages/flutter_html_video/pubspec.yaml | 6 +++- 7 files changed, 60 insertions(+), 15 deletions(-) diff --git a/packages/flutter_html_all/pubspec.yaml b/packages/flutter_html_all/pubspec.yaml index ae6a082b17..ad739c0e0f 100644 --- a/packages/flutter_html_all/pubspec.yaml +++ b/packages/flutter_html_all/pubspec.yaml @@ -2,6 +2,7 @@ name: flutter_html_all description: All optional flutter_html widgets, bundled into a single package. version: 3.0.0-beta.2 homepage: https://github.com/Sub6Resources/flutter_html +publish_to: none # Remove this line if you wish to publish to pub.dev environment: sdk: ">=2.12.0 <4.0.0" @@ -11,13 +12,35 @@ dependencies: flutter: sdk: flutter html: '>=0.15.0 <1.0.0' - flutter_html: ^3.0.0-beta.2 - flutter_html_audio: ^3.0.0-beta.2 - flutter_html_iframe: ^3.0.0-beta.2 - flutter_html_math: ^3.0.0-beta.2 - flutter_html_svg: ^3.0.0-beta.2 - flutter_html_table: ^3.0.0-beta.2 - flutter_html_video: ^3.0.0-beta.2 + flutter_html: + git: + url: git@github.com:uptech/flutter_html.git + ref: allow-srcdoc + flutter_html_audio: + git: + url: git@github.com:uptech/flutter_html.git + path: packages/flutter_html_audio + ref: allow-srcdoc + flutter_html_iframe: + url: git@github.com:uptech/flutter_html.git + path: packages/flutter_html_iframe + ref: allow-srcdoc + flutter_html_math: + url: git@github.com:uptech/flutter_html.git + path: packages/flutter_html_math + ref: allow-srcdoc + flutter_html_svg: + url: git@github.com:uptech/flutter_html.git + path: packages/flutter_html_svg + ref: allow-srcdoc + flutter_html_table: + url: git@github.com:uptech/flutter_html.git + path: packages/flutter_html_table + ref: allow-srcdoc + flutter_html_video: + url: git@github.com:uptech/flutter_html.git + path: packages/flutter_html_video + ref: allow-srcdoc dev_dependencies: flutter_test: diff --git a/packages/flutter_html_audio/pubspec.yaml b/packages/flutter_html_audio/pubspec.yaml index 3c414a36f1..7b2be15139 100644 --- a/packages/flutter_html_audio/pubspec.yaml +++ b/packages/flutter_html_audio/pubspec.yaml @@ -2,6 +2,7 @@ name: flutter_html_audio description: This extension package allows the