skip to Main Content

This is my code

Row(
  children: [
    Text("title"),
    Spacer(),
    ConstrainedBox(
      constraints: BoxConstraints(
          maxHeight: 28,
          minWidth: 45
      ),
      child: Container(
        decoration: BoxDecoration(
            color: Color(0x0A000000),
            borderRadius: BorderRadius.all(Radius.circular(4))
        ),
        child: TextField(
        ),
      ),
    ),
    SizedBox(width: 4,),
    Text("unit")
  ],
)

TextField will expand as much as possible, how could I make TextField wrap content without
using IntrinsicWidth.

2

Answers


  1. Try below code and remove Spacer form your widget use Expanded widget instead of that

    Row(
                children: [
                  const Text("Title"),
                  const SizedBox(width: 4),
                  Expanded(
                    child: Container(
                      decoration: const BoxDecoration(
                          color: Color(0x0A000000),
                          borderRadius: BorderRadius.all(Radius.circular(4))),
                      child: const TextField(),
                    ),
                  ),
                  const SizedBox(width: 4),
                  const Text("Unit")
                ],
              ),
    

    Result Screen-> image

    Login or Signup to reply.
  2. just you need to wrap the container with Flexible widget:

    Row(
      children: [
        Text("title"),
        Spacer(),
        Flexible(
          child: Container(
            decoration: BoxDecoration(
                color: Color(0x0A000000),
                borderRadius: BorderRadius.all(Radius.circular(4))
            ),
            child: TextField(),
          ),
        ),
        SizedBox(width: 4,),
        Text("unit")
      ],
    )
    

    This Working Fine

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search