在Stack中如果全部子元素都是Positioned元素, 那Stack必须有一个设置大小的父元素,否则会报错RenderStack object was given an infinite size during layout.

    在Stack中将需要高度自适应的子元素设置成非Positioned元素, 通过padding来调整该元素的位置,实例如下

    1. Stack(
    2. children: <Widget>[
    3. Positioned(
    4. top: setSize(18),
    5. right: setSize(6),
    6. child: Transform.rotate(
    7. angle: 3.14/4,
    8. child: Container(
    9. width: setSize(32),
    10. height: setSize(32),
    11. decoration: BoxDecoration(
    12. color: Color(0xff0CC6B6),
    13. borderRadius: BorderRadius.circular(setSize(4)),
    14. ),
    15. ),
    16. )
    17. ),
    18. Container(
    19. padding: EdgeInsets.only(right: setSize(16)),
    20. child: Container(
    21. padding: EdgeInsets.symmetric(horizontal: setSize(24), vertical: setSize(14)),
    22. constraints: BoxConstraints(
    23. maxWidth: setSize(470)
    24. ),
    25. decoration: BoxDecoration(
    26. borderRadius: BorderRadius.circular(setSize(10)),
    27. color: Color(0xff0CC6B6)
    28. ),
    29. child: Text('撒大发撒大发阿斯顿发送到发送到发送地方', style: TextStyle(color: Color(0xffffffff), fontSize: setFont(28), fontWeight: FontWeight.w400, height: 40/28)),
    30. ),
    31. )
    32. ],
    33. ),