Skip to content

Commit b24b264

Browse files
authored
Merge pull request #1 from tneotia/feature/irregular-tables
Fix sizing issues for images in flutter_layout_grid
2 parents fd5e64b + 48a65f0 commit b24b264

File tree

2 files changed

+60
-27
lines changed

2 files changed

+60
-27
lines changed

example/lib/main.dart

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ const htmlData = """
3535
<h4>Header 4</h4>
3636
<h5>Header 5</h5>
3737
<h6>Header 6</h6>
38+
<table>
39+
<colgroup>
40+
<col width="50%" />
41+
<col width="25%" />
42+
<col width="25%" />
43+
</colgroup>
44+
<thead>
45+
<tr><th>One</th><th>Two</th><th>Three</th></tr>
46+
</thead>
47+
<tbody>
48+
<tr>
49+
<td rowspan='2'>Rowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan</td><td>Data</td><td>Data</td>
50+
</tr>
51+
<tr>
52+
<td colspan="2"><img alt='Google' src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' /></td>
53+
</tr>
54+
</tbody>
55+
<tfoot>
56+
<tr><td>fData</td><td>fData</td><td>fData</td></tr>
57+
</tfoot>
58+
</table>
3859
<h3>Ruby Support:</h3>
3960
<p>
4061
<ruby>
@@ -60,27 +81,6 @@ const htmlData = """
6081
<p>
6182
<q>Famous quote...</q>
6283
</p>
63-
<table>
64-
<colgroup>
65-
<col width="50%" />
66-
<col width="25%" />
67-
<col width="25%" />
68-
</colgroup>
69-
<thead>
70-
<tr><th>One</th><th>Two</th><th>Three</th></tr>
71-
</thead>
72-
<tbody>
73-
<tr>
74-
<td rowspan='2'>Rowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan\nRowspan</td><td>Data</td><td>Data</td>
75-
</tr>
76-
<tr>
77-
<td colspan="2">Colpsan\nColpsan\nColpsan</td>
78-
</tr>
79-
</tbody>
80-
<tfoot>
81-
<tr><td>fData</td><td>fData</td><td>fData</td></tr>
82-
</tfoot>
83-
</table>
8484
<h3>Custom Element Support:</h3>
8585
<flutter></flutter>
8686
<flutter horizontal></flutter>
@@ -119,7 +119,6 @@ const htmlData = """
119119
Linking to <a href='https://github.com'>websites</a> has never been easier.
120120
</p>
121121
<h3>Image support:</h3>
122-
<!--
123122
<p>
124123
<img alt='Google' src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' />
125124
<a href='https://google.com'><img alt='Google' src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' /></a>

lib/src/replaced_element.dart

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:convert';
23
import 'dart:math';
34

@@ -127,13 +128,46 @@ class ImageContentElement extends ReplacedElement {
127128
context.parser.onImageError?.call(exception, stackTrace);
128129
},
129130
);
130-
imageWidget = Image.network(
131-
src,
132-
frameBuilder: (ctx, child, frame, _) {
133-
if (frame == null) {
131+
Completer<Size> completer = Completer();
132+
Image image = Image.network(src, frameBuilder: (ctx, child, frame, _) {
133+
if (frame == null) {
134+
completer.completeError("error");
135+
return child;
136+
} else {
137+
return child;
138+
}
139+
});
140+
image.image.resolve(ImageConfiguration()).addListener(
141+
ImageStreamListener(
142+
(ImageInfo image, bool synchronousCall) {
143+
var myImage = image.image;
144+
Size size = Size(myImage.width.toDouble(), myImage.height.toDouble());
145+
completer.complete(size);
146+
}, onError: (object, stacktrace) {
147+
completer.completeError(object);
148+
}
149+
),
150+
);
151+
imageWidget = FutureBuilder<Size>(
152+
future: completer.future,
153+
builder: (BuildContext buildContext, AsyncSnapshot<Size> snapshot) {
154+
if (snapshot.hasData) {
155+
return new Image.network(
156+
src,
157+
width: snapshot.data.width,
158+
height: snapshot.data.height,
159+
frameBuilder: (ctx, child, frame, _) {
160+
if (frame == null) {
161+
return Text(alt ?? "", style: context.style.generateTextStyle());
162+
}
163+
return child;
164+
},
165+
);
166+
} else if (snapshot.hasError) {
134167
return Text(alt ?? "", style: context.style.generateTextStyle());
168+
} else {
169+
return new CircularProgressIndicator();
135170
}
136-
return child;
137171
},
138172
);
139173
}

0 commit comments

Comments
 (0)