Skip to content

Commit d5fd222

Browse files
committed
Allow rewriting urls for network images
This is useful to apply a base url, but also could be used to swap domains or force an https schema
1 parent 02465f6 commit d5fd222

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

example/lib/main.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ class _MyHomePageState extends State<MyHomePage> {
178178
altWidget: (alt) => Text(alt),
179179
),
180180
(attr, _) => attr["src"] != null && attr["src"].startsWith("/wiki"):
181-
networkImageRender(baseUrl: "https://upload.wikimedia.org"),
181+
networkImageRender(
182+
mapUrl: (url) => "https://upload.wikimedia.org" + url),
182183
},
183184
onLinkTap: (url) {
184185
print("Opening $url...");

lib/image_render.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,13 @@ ImageRender assetImageRender({
9090

9191
ImageRender networkImageRender({
9292
Map<String, String> headers,
93-
String baseUrl,
93+
String Function(String) mapUrl,
9494
double width,
9595
double height,
9696
Widget Function(String) altWidget,
9797
}) =>
9898
(context, attributes, element) {
99-
final src =
100-
baseUrl != null ? baseUrl + _src(attributes) : _src(attributes);
99+
final src = mapUrl?.call(_src(attributes)) ?? _src(attributes);
101100
precacheImage(
102101
NetworkImage(
103102
src,

0 commit comments

Comments
 (0)