Skip to content

Instantly share code, notes, and snippets.

@daohoangson
Created September 21, 2019 09:59
Show Gist options
  • Save daohoangson/111e103f92e0261e0077855f4e9f5e0a to your computer and use it in GitHub Desktop.
Save daohoangson/111e103f92e0261e0077855f4e9f5e0a to your computer and use it in GitHub Desktop.
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;
}
@daohoangson
Copy link
Author

In v0.2.3+2, the buildImageFromUrl method signature have changed. The sample code must be updated to avoid build error:

  @override
  ImageProvider buildImageFromUrl(String url) =>
      url?.isNotEmpty == true ? NetworkImage(url) : null;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment