auto_size_text icon indicating copy to clipboard operation
auto_size_text copied to clipboard

Does not work inside an IntrinsicHeight and row

Open stargazing-dino opened this issue 5 years ago • 10 comments

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.

card_screenshot

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

stargazing-dino avatar Sep 05 '19 22:09 stargazing-dino

Is there any workaround / hack available?

beevelop avatar Jun 02 '20 09:06 beevelop

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.

fredecodes avatar Aug 31 '20 02:08 fredecodes

if you use the AutoSizeText widget with maxLines = 1, then you can wrap the widget inside a SizedBox and define the height

talski avatar Sep 03 '20 00:09 talski

Same issue here as well

rdehouss avatar Dec 20 '20 12:12 rdehouss

+1

saveKenny avatar Mar 31 '21 19:03 saveKenny

+1

nerdware-timmmi avatar May 25 '21 21:05 nerdware-timmmi

+1

luqmanhakem avatar Jun 03 '21 00:06 luqmanhakem

+1

offline-first avatar Oct 13 '21 16:10 offline-first

I am facing the same issue

moazelsawaf avatar Feb 15 '22 03:02 moazelsawaf

I am facing the same issue

rajeshbdabhi avatar Oct 11 '22 05:10 rajeshbdabhi