Skip to content

Commit 52205fb

Browse files
committed
Potentially fix small images being center aligned
1 parent 20dfaa4 commit 52205fb

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

lib/image_render.dart

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,26 @@ ImageRender networkImageRender({
141141
future: completer.future,
142142
builder: (BuildContext buildContext, AsyncSnapshot<Size> snapshot) {
143143
if (snapshot.hasData) {
144-
return AspectRatio(
145-
aspectRatio: _aspectRatio(attributes, snapshot),
146-
child: Image.network(
147-
src,
148-
headers: headers,
149-
width: width ?? _width(attributes) ?? snapshot.data!.width,
150-
height: height ?? _height(attributes),
151-
frameBuilder: (ctx, child, frame, _) {
152-
if (frame == null) {
153-
return altWidget?.call(_alt(attributes)) ??
154-
Text(_alt(attributes) ?? "", style: context.style.generateTextStyle());
155-
}
156-
return child;
157-
},
144+
return Container(
145+
constraints: BoxConstraints(
146+
maxWidth: width ?? _width(attributes) ?? snapshot.data!.width,
147+
maxHeight: (width ?? _width(attributes) ?? snapshot.data!.width) / _aspectRatio(attributes, snapshot)
148+
),
149+
child: AspectRatio(
150+
aspectRatio: _aspectRatio(attributes, snapshot),
151+
child: Image.network(
152+
src,
153+
headers: headers,
154+
width: width ?? _width(attributes) ?? snapshot.data!.width,
155+
height: height ?? _height(attributes),
156+
frameBuilder: (ctx, child, frame, _) {
157+
if (frame == null) {
158+
return altWidget?.call(_alt(attributes)) ??
159+
Text(_alt(attributes) ?? "", style: context.style.generateTextStyle());
160+
}
161+
return child;
162+
},
163+
),
158164
),
159165
);
160166
} else if (snapshot.hasError) {

0 commit comments

Comments
 (0)