Flutter parent width adaptive child control width

Requirements: The control adapts to the width of the gold coin

image.png

Steps:
1. The container does not set the width, but the constraint padding needs to be set;
2. The text uses the Flexible form;

Container(
         height: 24.dp,
         padding: EdgeInsetsDirectional.only(start: 8.dp, end: 5.dp),
         decoration: BoxDecoration(
           color: Color(0XFFFFFFFF).withOpacity(0.1),
           borderRadius: BorderRadius.circular(12.dp),
         ),
         child: Row(
           mainAxisSize: MainAxisSize.min,
           crossAxisAlignment: CrossAxisAlignment.center,
           children: [
             Container(
               margin: EdgeInsetsDirectional.only(end: 3.dp),
               child:  R.img(
                 'gift_star_coin.png',
                 width: 16.dp,
                 height: 16.dp,
                 package: ComponentManager.MANAGER_GIFT,
               ),
             ),
             Flexible(
               child: Text(
                 _data.totalMoney.toString(),
                 textAlign: TextAlign.center,
                 style: TextStyle(
                   fontSize: 12.0,
                   color: Color(0XFF858585),
                 ),
               ),
             ),
             Container(
               child: R.img(
                 'gift_in_price.png',
                 width: 13.dp,
                 height: 13.dp,
                 package: ComponentManager.MANAGER_GIFT,
               ),
             ),
           ],
         ),
       ),

Guess you like

Origin blog.csdn.net/qq_27981847/article/details/132151721