"An InputDecorator, which is typically created by a TextField" not fixed by wrapping in Expanded

4,453 views
Skip to first unread message

Guyren Howe

unread,
Jan 12, 2020, 6:31:59 PM1/12/20
to Flutter Development (flutter-dev)
I have this:

        Expanded(
          child
: TextField(
            controller
: _controller
          )
       
)

Inside a Column, inside a row, in the body of Scaffold. I get the error "An InputDecorator, which is typically created by a TextField, cannot have an unbounded width".

The advice I can find says this is fixed by wrapping the TextField in an Expanded, but it already is.

Guyren Howe

unread,
Jan 12, 2020, 7:00:17 PM1/12/20
to Flutter Development (flutter-dev)
Here is a demonstration:

import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home:
        Scaffold(
          body: Example()
        )
      )
  );
}

class Example extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ExampleState();
  }
}

class _ExampleState extends State<Example> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Row(
          children: [Column(
            children: [
              Text('Foo'),
              Expanded(
                child: TextField()
              )
            ]
          )]
        )
      );
  }
}



Raavi S, VU2ZOE

unread,
Jan 13, 2020, 3:38:08 AM1/13/20
to Guyren Howe, Flutter Development (flutter-dev)
Could you please try Flexible or SizedBox instead of Expanded?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/23303375-ec2f-4dcb-b85d-58c35ff9fc14%40googlegroups.com.


--

Thanks & Regards ✍︎
 Raavi S
 VU2ZOE
 +91-9000321902

Justin McCandless

unread,
Jan 13, 2020, 11:53:18 AM1/13/20
to Raavi S, VU2ZOE, Guyren Howe, Flutter Development (flutter-dev)
I think the exact solution for you will depend on what you're trying to do with the layout.  Wrapping the TextField in a SizedBox will stop the error if you want to specify a pixel size for the TextField.  How do you want the layout to look exactly?


Justin


Guyren Howe

unread,
Jan 13, 2020, 1:25:39 PM1/13/20
to Flutter Development (flutter-dev), Flutter Development (flutter-dev)
I’m creating a UI like Slack. A list of users in the left column. The right column is a timeline, below which is a text entry box, and below that a set of buttons for adding pictures and such to the timeline.

Guyren Howe

unread,
Jan 14, 2020, 12:00:15 AM1/14/20
to Flutter Development (flutter-dev)
A SizedBox with a fixed width works, but is not suitable. I want it to be the width of the column containing it. My best reading of the docs is that Expanded should do this but it doesn’t work.

How do I get a fixed height and the same width as the parent. Ideally, I would like an explanation also of why Expanded doesn’t do that.

Guyren Howe

unread,
Jan 15, 2020, 2:37:11 PM1/15/20
to Flutter Development (flutter-dev)
I've tried various different constraining widgets (including Flexible and SizedBox). I can't find one that does this simple thing:

- fixed height (ideally derived from the text field child)
- same width as column it's in

The closest I can come is with a fixed-size SizeBox, which isn't going to adapt to different orientations, sizes of display and such.

This doesn't seem like it should be difficult. I'd love ideally to know why an Expanded doesn't work, and a general theory of how to work out how to do layouts.


On Monday, January 13, 2020 at 9:00:15 PM UTC-8, Guyren Howe wrote:
A SizedBox with a fixed width works, but is not suitable. I want it to be the width of the column containing it. My best reading of the docs is that Expanded should do this but it doesn’t work.

How do I get a fixed height and the same width as the parent. Ideally, I would like an explanation also of why Expanded doesn’t do that.

On Jan 13, 2020, at 10:25 , Guyren Howe <guy...@gmail.com> wrote:

I’m creating a UI like Slack. A list of users in the left column. The right column is a timeline, below which is a text entry box, and below that a set of buttons for adding pictures and such to the timeline.
On Jan 13, 2020, 08:53 -0800, Justin McCandless <jmcca...@google.com>, wrote:
I think the exact solution for you will depend on what you're trying to do with the layout.  Wrapping the TextField in a SizedBox will stop the error if you want to specify a pixel size for the TextField.  How do you want the layout to look exactly?



Justin McCandless

unread,
Jan 15, 2020, 4:05:06 PM1/15/20
to Guyren Howe, Flutter Development (flutter-dev)
Is this what you mean?  Here's a Container with a fixed height and a width that depends on its parent: https://dartpad.dartlang.org/7fbb51e12dc2bfe21a99057d050fef96

Let me know if I'm misunderstanding what you're looking for, or feel free to modify that code to illustrate what you need.


Justin


--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.

Gregg Reynolds

unread,
Jan 15, 2020, 7:36:19 PM1/15/20
to Guyren Howe, Flutter Development (flutter-dev)
Try putting it inside a row inside your column? Expansion works in mainAxis dimension, so you need to fiddle with nestings of rows and columns.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.

Tom Gilmour

unread,
Jan 15, 2020, 10:42:34 PM1/15/20
to Flutter Development (flutter-dev)
I believe the column should be "Expanded":

home: Row(
          children: [
            Expanded( 
              child: Column(
                children: [             
                  Text('This is the text and there\'s enough to wrap'),              
                  TextField()
                ]
              )
            )
          ]
        )
To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages