Skip to content

Commit

Permalink
IB: Bringup Simulator embeds extension using webview.
Browse files Browse the repository at this point in the history
* flutter_markdown has some issues because of which we are using our own fork of the same.
(manjotsidhu/packages@29bb87f)
* We have updated flutter_markdown from 0.5.2 -> 0.6.2.
* flutter_html needed update because of Sub6Resources/flutter_html#500.
* flutter_html updated from 1.0.2 -> 1.3.0, which depends on flutter_svg, flutter_svg updated from 0.19.3
-> 0.20.0-nullsafety.3

Signed-off-by: Manjot Sidhu <[email protected]>
  • Loading branch information
manjotsidhu authored and Nitish145 committed Jul 21, 2021
1 parent 2fa8ec7 commit 7e76b63
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
37 changes: 37 additions & 0 deletions lib/ui/views/ib/builders/ib_webview_builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_html/html_parser.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:markdown/markdown.dart' as md;

class IbWebViewBuilder extends MarkdownElementBuilder {
final BuildContext context;

IbWebViewBuilder({this.context});

@override
Widget visitElementAfter(md.Element element, TextStyle preferredStyle) {
var textContent = element.textContent;

return Html(
data: textContent,
customRender: {
'iframe': (RenderContext context, Widget child, attributes, _) {
final width = MediaQuery.of(context.buildContext).size.width;
final height = (width * 9) / 16;

return SizedBox(
width: width,
height: height,
child: WebView(
initialUrl: attributes['src'],
javascriptMode: JavascriptMode.unrestricted,
initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy.always_allow,
),
);
},
},
);
}
}
6 changes: 6 additions & 0 deletions lib/ui/views/ib/ib_page_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:mobile_app/models/ib/ib_chapter.dart';
import 'package:mobile_app/models/ib/ib_content.dart';
import 'package:mobile_app/models/ib/ib_page_data.dart';
import 'package:mobile_app/ui/views/base_view.dart';
import 'package:mobile_app/ui/views/ib/builders/ib_webview_builder.dart';
import 'package:mobile_app/ui/views/ib/syntaxes/ib_embed_syntax.dart';
import 'package:mobile_app/ui/views/ib/syntaxes/ib_filter_syntax.dart';
import 'package:mobile_app/ui/views/ib/syntaxes/ib_md_tag_syntax.dart';
import 'package:mobile_app/viewmodels/ib/ib_page_viewmodel.dart';
Expand Down Expand Up @@ -66,8 +68,12 @@ class _IbPageViewState extends State<IbPageView> {
return MarkdownBody(
data: data.content,
selectable: true,
blockBuilders: {
'iframe': IbWebViewBuilder(context: context),
},
extensionSet: md.ExtensionSet(
[
IbEmbedSyntax(),
IbFilterSyntax(),
IbMdTagSyntax(),
...md.ExtensionSet.gitHubFlavored.blockSyntaxes
Expand Down
16 changes: 16 additions & 0 deletions lib/ui/views/ib/syntaxes/ib_embed_syntax.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:markdown/markdown.dart' as md;

class IbEmbedSyntax extends md.BlockSyntax {
IbEmbedSyntax() : super();

@override
md.Node parse(md.BlockParser parser) {
var text = parser.current;
parser.advance();

return md.Element.text('iframe', text);
}

@override
RegExp get pattern => RegExp(r'^<iframe.+>.+<\/iframe>');
}
10 changes: 6 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ dependencies:
cupertino_icons: ^1.0.2
datetime_picker_formfield: ^2.0.0
flutter_facebook_auth: ^3.3.2
flutter_html: ^1.0.2
flutter_html: ^1.3.0
flutter_icons: ^1.1.0
flutter_keyboard_visibility: ^5.0.0
flutter_summernote: ^0.2.3
flutter_svg: ^0.19.3
flutter_svg: ^0.20.0-nullsafety.3
flutter_typeahead: ^3.0.0-nullsafety.0
get: ^3.26.0
get_it: ^6.0.0
Expand All @@ -48,12 +48,14 @@ dependencies:
timeago: ^3.0.2
transparent_image: ^1.0.0
url_launcher: ^6.0.2
flutter_markdown: ^0.5.2
flutter_markdown:
git:
url: git://github.com/manjotsidhu/packages.git
path: packages/flutter_markdown

dev_dependencies:
flutter_test:
sdk: flutter
flutter_launcher_icons: ^0.8.1
pedantic: ^1.9.0

dependency_overrides:
Expand Down

0 comments on commit 7e76b63

Please sign in to comment.