Skip to content

Commit 460dc0b

Browse files
authored
Fix min constraints being 100% (#761)
Related to #742
1 parent b89ae37 commit 460dc0b

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

packages/core/lib/src/widgets/css_sizing.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,17 @@ class _RenderCssSizing extends RenderProxyBox {
209209
min(c.maxHeight, _maxHeight?.clamp(0.0, c.maxHeight) ?? c.maxHeight);
210210
final maxWidth =
211211
min(c.maxWidth, _maxWidth?.clamp(0.0, c.maxWidth) ?? c.maxWidth);
212-
final minHeight =
212+
213+
final __minHeight =
213214
min(maxHeight, _minHeight?.clamp(0.0, c.maxHeight) ?? c.minHeight);
214-
final minWidth =
215+
final __minWidth =
215216
min(maxWidth, _minWidth?.clamp(0.0, c.maxWidth) ?? c.minWidth);
217+
// ignore min value if it's infinite
218+
final minHeight = __minHeight.isFinite ? __minHeight : .0;
219+
final minWidth = __minWidth.isFinite ? __minWidth : .0;
216220

217-
final effectiveMinHeight =
218-
c.hasTightHeight && _minHeight == null ? 0.0 : minHeight;
219-
final effectiveMinWidth =
220-
c.hasTightWidth && _minWidth == null ? 0.0 : minWidth;
221-
final __preferredHeight =
222-
_preferredHeight?.clamp(effectiveMinHeight, maxHeight);
223-
final __preferredWidth =
224-
_preferredWidth?.clamp(effectiveMinWidth, maxWidth);
221+
final __preferredHeight = _preferredHeight?.clamp(minHeight, maxHeight);
222+
final __preferredWidth = _preferredWidth?.clamp(minWidth, maxWidth);
225223
// ignore preferred value if it's infinite
226224
final preferredHeight =
227225
__preferredHeight?.isFinite == true ? __preferredHeight : null;

packages/core/test/style_sizing_test.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,27 @@ void main() {
246246
),
247247
);
248248
});
249+
250+
testWidgets('renders 100%', (WidgetTester tester) async {
251+
const html = '<div style="min-height: 100%">Foo</div>';
252+
final explained = await explain(
253+
tester,
254+
null,
255+
hw: SingleChildScrollView(
256+
child: HtmlWidget(
257+
html,
258+
key: hwKey,
259+
),
260+
),
261+
);
262+
expect(
263+
explained,
264+
equals(
265+
'[CssSizing:height≥100.0%,width=100.0%,child='
266+
'[RichText:(:Foo)]]',
267+
),
268+
);
269+
});
249270
});
250271

251272
group('min-width', () {
@@ -306,6 +327,28 @@ void main() {
306327
),
307328
);
308329
});
330+
331+
testWidgets('renders 100%', (WidgetTester tester) async {
332+
const html = '<div style="min-width: 100%">Foo</div>';
333+
final explained = await explain(
334+
tester,
335+
null,
336+
hw: SingleChildScrollView(
337+
scrollDirection: Axis.horizontal,
338+
child: HtmlWidget(
339+
html,
340+
key: hwKey,
341+
),
342+
),
343+
);
344+
expect(
345+
explained,
346+
equals(
347+
'[CssSizing:width≥100.0%,width=100.0%,child='
348+
'[RichText:(:Foo)]]',
349+
),
350+
);
351+
});
309352
});
310353

311354
group('width', () {

0 commit comments

Comments
 (0)