当前位置:   article > 正文

Flutter父宽度自适应子控件的宽度_flutter 父组件适应子组件的大小

flutter 父组件适应子组件的大小

需求: 控件随着金币进行自适应宽度

image.png

步骤:
1、Container不设置宽度,需要设置约束padding;
2、文本使用Flexible形式;

  1. Container(
  2. height: 24.dp,
  3. padding: EdgeInsetsDirectional.only(start: 8.dp, end: 5.dp),
  4. decoration: BoxDecoration(
  5. color: Color(0XFFFFFFFF).withOpacity(0.1),
  6. borderRadius: BorderRadius.circular(12.dp),
  7. ),
  8. child: Row(
  9. mainAxisSize: MainAxisSize.min,
  10. crossAxisAlignment: CrossAxisAlignment.center,
  11. children: [
  12. Container(
  13. margin: EdgeInsetsDirectional.only(end: 3.dp),
  14. child: R.img(
  15. 'gift_star_coin.png',
  16. width: 16.dp,
  17. height: 16.dp,
  18. package: ComponentManager.MANAGER_GIFT,
  19. ),
  20. ),
  21. Flexible(
  22. child: Text(
  23. _data.totalMoney.toString(),
  24. textAlign: TextAlign.center,
  25. style: TextStyle(
  26. fontSize: 12.0,
  27. color: Color(0XFF858585),
  28. ),
  29. ),
  30. ),
  31. Container(
  32. child: R.img(
  33. 'gift_in_price.png',
  34. width: 13.dp,
  35. height: 13.dp,
  36. package: ComponentManager.MANAGER_GIFT,
  37. ),
  38. ),
  39. ],
  40. ),
  41. ),
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/227307
推荐阅读
相关标签
  

闽ICP备14008679号