0

I need a TextField inside Wrap widget. But it throws this error,

The _RenderDecoration class does not support dry layout

....

....

════════ Exception caught by scheduler library ════════

Updated layout information required for RenderFlex#87b02 relayoutBoundary=up7 NEEDS-LAYOUT NEEDS-PAINT to calculate semantics.

The Parent of the Wrap widget is a Column with mainAxisSize.min. And the Column is inside an AlertDialog's content. And also I need dynamic height. So, I didn't use any fixed height SizedBox. Here is the code example,

AlertDialog(
  scrollable: true,
  content: Column(
    mainAxisSize: MainAxisSize.min,
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      SomeWidgets(),
      Wrap(
        spacing: 5,
        runSpacing: 5,
        crossAxisAlignment: WrapCrossAlignment.center,
        children: [
          Text(t.someText),
          Container(
            width: 50.0,
            height: 50.0,
            color: theme.colorScheme.primary,
            alignment: Alignment.center,
            child: TextField(
              textAlign: TextAlign.center,
              keyboardType: TextInputType.number,
              controller: _controller,
              decoration: const InputDecoration(
                contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
                isDense: true,
                filled: true,
              ),
              onChanged: (v) {},
            ),
          ),
          Text(t.someText),
        ],
      ),
      SomeWidgets(),
    ],
  ),
)
Santo Shakil
  • 981
  • 2
  • 13
  • 27

3 Answers3

1

Wrap your Wrap widget with Flexible or provide height on wrap widget inside dialog.

On scrollable: false use SingleChildScrollView for dynamic height

showDialog(
    context: context,
    builder: (c) => AlertDialog(
          scrollable: false,
          content: SingleChildScrollView(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Flexible(
                  child: Wrap(
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
0

Add Flexible inside Column.

Reference : https://api.flutter.dev/flutter/widgets/Flexible-class.html

AlertDialog(
    content: Column(mainAxisSize: MainAxisSize.min, children: [
  Flexible( // Added
      child: Wrap(
    spacing: 5,
    runSpacing: 5,
    crossAxisAlignment: WrapCrossAlignment.center,
    children: []
    ))
    ])
Yashraj
  • 1,025
  • 1
  • 5
  • 22
0

It is a flutter bug. Here is the solution.

Essential parts: As long as Flutter's implementation of TextField blows up during dry layout, the only way we can avoid the bug is to prevent the dry layout call from being invoked on TextField.

We came up with slight alterations on IntrinsicWidth and IntrinsicHeight that use the child's intrinsic dimensions instead of invoking the child's dry layout method: https://gist.github.com/matthew-carroll/65411529a5fafa1b527a25b7130187c6

Then you can do something like:

Wrap(
  children: [
    DryIntrinsicWidth(
      child: TextField(...),
    ),
  ],
);
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34724906) – doneforaiur Jul 25 '23 at 09:47