解决flutter/src/rendering/stack.dart‘: Failed assertion: line 588 pos 12: ‘size.isFinite‘: is not true

flutter代码如下,后报错

Container(
            child: Stack(
              alignment: Alignment.center,
              fit: StackFit.loose,
              children: [
                Positioned(
                    left: 0,
                    child: Text("¥500"),
                )
                ,Positioned(
                  right: 0,
                  child: GestureDetector(
                    child: Icon(Icons.add_shopping_cart),
                  ),
                )
              ],
            ),
          )

报错内容如下

package:flutter/src/rendering/stack.dart': Failed assertion: line 588 pos 12: 'size.isFinite': is not true
RenderBox was not laid out: RenderStack#987f2 relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1940 pos 12: 'hasSize'

这个报错的意思是再渲染盒子的时候需要一个尺寸。
然后我在上述代码添加了一个height就可以了

Container(       
            height: 30,
            child: Stack(
              alignment: Alignment.center,
              fit: StackFit.loose,
              children: [
                Positioned(
                    left: 2,
                    child: Text(
                        "¥500",
                      style: TextStyle(
                        color: Colors.red,
                        fontSize: 20
                      ),
                    ),
                )
                ,Positioned(
                  right: 5,
                  child: GestureDetector(
                    child: Icon(
                        Icons.add_shopping_cart,
                        color: Colors.red,
                    ),
                  ),
                )
              ],
            ),
          )

你可能感兴趣的:(flutter,dart,flutter)