Home > database >  BoxConstraints forces an infinite height[error]
BoxConstraints forces an infinite height[error]

Time:11-27

This is my code.. I am getting error saying that 'BoxConstraints forces an infinite height.' and then a description and i am new to flutter i am not getting a way to solve this.

  body:SingleChildScrollView(
    child: Stack(
      fit: StackFit.expand,
      children: [
        Image(
          color: Colors.black12,
          colorBlendMode: BlendMode.darken,
          image: AssetImage('images/Alone.jpg'),
          fit: BoxFit.cover,
        ),
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Show('Alone is Stronger', 'y'),
          ],
        )
      ],
    ),
  ),

This is my Show widget.

Widget Show(String x,String y){
return
    Container(
    margin: EdgeInsets.fromLTRB(10, 5, 10, 2),
    width: 400,
    decoration: BoxDecoration(
      color: Colors.white10,
      borderRadius: BorderRadius.circular(10),
    ),
    padding: EdgeInsets.all(10),
    child: Text(
      '$x',
          style: TextStyle(
        fontSize: 20,
         fontWeight: FontWeight.bold,
      color: Colors.yellowAccent,
           ),
        ),
     ); 
  }

Lot of questions already here with same problem but i am not getting where the problem is. Thanks in advance

CodePudding user response:

From your code-snippet, I can understand you are trying to have a background on body.

SingleChildScrollView provide infinite height and while Stack is its child and use parent size, it will get infinite height and through errors.

In your case, the widget structure will be

  body: Stack(
        fit: StackFit.expand,
        children: [
          Image(
            color: Colors.black12,
            colorBlendMode: BlendMode.darken,
            image: AssetImage('images/Alone.jpg'),
            fit: BoxFit.cover,
          ),
          SingleChildScrollView(
              child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Show('Alone is Stronger', 'y'),
            ],
          ))
        ],
      ),
  • Related