auto_size_text
auto_size_text copied to clipboard
Does not work inside an IntrinsicHeight and row
Hi!
Steps to Reproduce Create a listview and add an item that looks like the following code block from here https://stackoverflow.com/a/51157072/8213910
Here is a minimal example
class ExampleWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: 3,
itemBuilder: (context, _) {
return Card(
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
height: 40,
width: 20.0,
color: Colors.amber,
),
Expanded(
child: AutoSizeText('hello'),
),
],
),
),
);
},
),
);
}
}
It throws this:
The following assertion was thrown during performLayout():
LayoutBuilder does not support returning intrinsic dimensions.
Calculating the intrinsic dimensions would require running the layout callback speculatively, which might mutate the live render object tree.
User-created ancestor of the error-causing widget was
Card
lib\pages\home.dart:28
When the exception was thrown, this was the stack
#0 _RenderLayoutBuilder._debugThrowIfNotCheckingIntrinsics.<anonymous closure>
package:flutter/…/widgets/layout_builder.dart:263
#1 _RenderLayoutBuilder._debugThrowIfNotCheckingIntrinsics
package:flutter/…/widgets/layout_builder.dart:270
#2 _RenderLayoutBuilder.computeMaxIntrinsicHeight
package:flutter/…/widgets/layout_builder.dart:234
#3 RenderBox._computeIntrinsicDimension.<anonymous closure>
package:flutter/…/rendering/box.dart:1290
#4 _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:291:23)
...
The following RenderObject was being processed when the exception was fired: RenderIntrinsicHeight#dd578 relayoutBoundary=up11 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
RenderObject: RenderIntrinsicHeight#dd578 relayoutBoundary=up11 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: <none> (can use size)
constraints: BoxConstraints(w=675.4, 0.0<=h<=Infinity)
size: Size(675.4, 40.0)
child: RenderFlex#ef52d NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: <none> (can use size)
constraints: BoxConstraints(w=675.4, h=40.0)
size: Size(675.4, 40.0)
direction: horizontal
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: stretch
textDirection: ltr
verticalDirection: down
child 1: RenderConstrainedBox#34546 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
constraints: BoxConstraints(0.0<=w<=Infinity, h=40.0)
size: Size(20.0, 40.0)
additionalConstraints: BoxConstraints(w=20.0, h=40.0)
child: RenderDecoratedBox#f84cb NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: <none> (can use size)
constraints: BoxConstraints(w=20.0, h=40.0)
size: Size(20.0, 40.0)
decoration: BoxDecoration
color: MaterialColor(primary value: Color(0xffffc107))
configuration: ImageConfiguration(bundle: PlatformAssetBundle#f4e9c(), devicePixelRatio: 2.6, locale: en_US, textDirection: TextDirection.ltr, platform: android)
child 2: _RenderLayoutBuilder#14596 NEEDS-LAYOUT NEEDS-PAINT
parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
constraints: MISSING
size: MISSING
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by rendering library ═════════════════════════════════
LayoutBuilder does not support returning intrinsic dimensions.
User-created ancestor of the error-causing widget was
Card
lib\pages\home.dart:28
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by rendering library ═════════════════════════════════
LayoutBuilder does not support returning intrinsic dimensions.
User-created ancestor of the error-causing widget was
Card
lib\pages\home.dart:28
════════════════════════════════════════════════════════════════════════════════
Screenshots I want to create a card with date text on the left that will scale and content on the right. I don't want to use a FittedBox solution as the text grows too much on landscape and looks ugly.
Version
Flutter 1.9.1+hotfix.1 • channel beta • https://github.com/flutter/flutter.git
Framework • revision a1fb3fabec (2 days ago) • 2019-09-03 18:07:52 -0700
Engine • revision cc88fa45db
Tools • Dart 2.5.0
- auto_size_text version: 2.1.0
Is there any workaround / hack available?
Having the same issue. AutoSizeText in the widget tree under an InstrinsicHeight node gives the exception as reported in the original post above. I assume this isn't something that can be fixed, ie the issue is not with AutoSizeText but rather would happen with any use of LayoutBuilder underneath IntrinsicHeight.
if you use the AutoSizeText widget with maxLines = 1, then you can wrap the widget inside a SizedBox and define the height
Same issue here as well
+1
+1
+1
+1
I am facing the same issue
I am facing the same issue