forked from Sub6Resources/flutter_html
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathiframe_mobile.dart
More file actions
67 lines (58 loc) · 2.07 KB
/
iframe_mobile.dart
File metadata and controls
67 lines (58 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:webview_flutter/webview_flutter.dart';
class IframeWidget extends StatelessWidget {
final NavigationDelegate? navigationDelegate;
final ExtensionContext extensionContext;
const IframeWidget({
Key? key,
required this.extensionContext,
this.navigationDelegate,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final WebViewController controller = WebViewController();
final sandboxMode = extensionContext.attributes["sandbox"];
controller.setJavaScriptMode(
sandboxMode == null || sandboxMode == "allow-scripts"
? JavaScriptMode.unrestricted
: JavaScriptMode.disabled);
if (navigationDelegate != null) {
controller.setNavigationDelegate(navigationDelegate!);
}
final UniqueKey key = UniqueKey();
final givenWidth =
double.tryParse(extensionContext.attributes['width'] ?? "");
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,
child: CssBoxWidget(
style: extensionContext.styledElement!.style,
childIsReplaced: true,
child: WebViewWidget(
controller: controller
..loadRequest(
Uri.tryParse(extensionContext.attributes['src'] ?? "") ??
Uri()),
key: key,
gestureRecognizers: {Factory(() => VerticalDragGestureRecognizer())},
),
),
);
}
}