Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use spacer inside a column that is wrapped with singlechildscrollview?

Tags:

flutter

I am trying to use spacer inside a column that is wrapped with singlechildscrollview and it gives me an error.

RenderFlex children have non-zero flex but incoming height constraints are unbounded.

here is my widget

class Test extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Form(
        child: SingleChildScrollView(
      child: Column(
        children: <Widget>[
          TextFormField(),
          TextFormField(),
          //Spacer()
          Divider(),
          Icon(Icons.block)
        ],
      ),
    ));
  }
}

what should i use? your help is appreciated

like image 353
Ali Alqallaf Avatar asked Sep 12 '25 11:09

Ali Alqallaf


1 Answers

You can try this out, I added an example using your code, it works:

class Test extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(body: LayoutBuilder(
      builder: (context, constraint) {
        return Form(
          child: SingleChildScrollView(
            child: ConstrainedBox(
              constraints: BoxConstraints(minHeight: constraint.maxHeight),
              child: IntrinsicHeight(
                child: Column(
                  children: <Widget>[
                    TextFormField(),
                    TextFormField(),
                    Spacer(),
                    Divider(),
                    Icon(Icons.block)
                  ],
                ),
              ),
            ),
          ),
        );
      },
    ));
  }
}

Check this Github issue for much details on the solution above: Wrapping a Column with an expanded in a SingleChildScrollView throws an exception

like image 179
V.N Avatar answered Sep 15 '25 04:09

V.N