Closed himanshu64 closed 2 years ago
working when i tried to add instagram embed in individual new project, but it crashes in an existing project , need some help please
class _Html extends StatelessWidget {
final String html;
final String title;
const _Html({Key key, this.html, this.title}) : super(key: key);
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: Text(title)),
body: SingleChildScrollView(
child: HtmlWidget(
html,
customStylesBuilder: (e) {
switch (e.localName) {
case 'em':
return {'color': '#f00'};
}
return null;
},
customWidgetBuilder: (e) {
if (e.localName == 'blockquote') {
switch (e.attributes['class']) {
case 'instagram-media':
return buildForInstagram(e.outerHtml);
case 'twitter-tweet':
return buildForTwitter(e.outerHtml);
}
}
return null;
},
webView: true,
),
),
);
Widget buildForInstagram(String html) => WebView(
Uri.dataFromString(
"""<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
$html
<script async src="https://www.instagram.com/embed.js"></script>
</body>
</html>""",
mimeType: 'text/html',
encoding: Encoding.getByName('utf-8'),
).toString(),
aspectRatio: 16 / 9,
autoResize: true,
);
Widget buildForTwitter(String html) => WebView(
"https://api.flutter-widget-from-html.vercel.app/iframe.ts?body=${Uri.encodeComponent(html + '<script async src="https://platform.twitter.com/widgets.js"></script>')}",
aspectRatio: 16 / 9,
autoResize: true,
);
}
Some other people reported similar issues with PlatformView
:
I noticed you were testing with a x86 emulator? Can you try on a real device and/or ARM emulator?
yes i tried with real device also it failed again
This is an old issue, I'm closing it today. Since this works for a fresh project while crashes on an existing one, further information is needed. Feel free to open a new issue if you are still struggling.