Created
September 21, 2019 09:59
-
-
Save daohoangson/111e103f92e0261e0077855f4e9f5e0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart'; | |
const html = """ | |
<figure> | |
<img src="https://media.giphy.com/media/6VoDJzfRjJNbG/giphy-downsized.gif" width="250" height="171" /> | |
<figcaption>Source: <a href="https://gph.is/QFgPA0">https://gph.is/QFgPA0</a></figcaption> | |
</figure> | |
"""; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) => MaterialApp( | |
home: Scaffold( | |
appBar: AppBar(title: Text('Image.network')), | |
body: SingleChildScrollView( | |
child: HtmlWidget( | |
html, | |
factoryBuilder: (hwc) => _MyWidgetFactory(hwc), | |
), | |
), | |
), | |
); | |
} | |
class _MyWidgetFactory extends WidgetFactory { | |
_MyWidgetFactory(HtmlWidgetConfig config) : super(config); | |
@override | |
Widget buildImageFromUrl(String url) => | |
url?.isNotEmpty == true ? Image.network(url, fit: BoxFit.cover) : null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In
v0.2.3+2
, thebuildImageFromUrl
method signature have changed. The sample code must be updated to avoid build error: