flutter - 固定小部件在一行中的位置
问题描述
我的行中有两个小部件,一个文本小部件和一个计数器小部件。文本小部件包含在计数器增加/减少时增加和减少的值。现在,当值增加时,它会将计数器向右推。我该如何防止这种情况发生?我希望柜台保持在固定位置。
Widget build(BuildContext context) {
var loyaltyPrice = Provider.of<Cart>(context, listen: false).loyaltyPrice;
return
Card(
color:Colors.red[100],
margin: EdgeInsets.symmetric(
horizontal: 15,
vertical: 4,
),
child: Padding(
padding: const EdgeInsets.all(5),
child:Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Row(
children: [
Text('- \Tsh. $loyaltyPrice ',style:TextStyle(color:Colors.red)),
SizedBox(width:120),
LoyaltyCounterView(),
]),
],
)
),
);
}
}
解决方案
而不是在您的小部件之间使用大小框,用容器包装您的文本小部件并为其设置宽度
Row(
children: [
Container(width:your width,child: Text('- \Tsh. $loyaltyPrice ',style:TextStyle(color:Colors.red)),)
LoyaltyCounterView(),
]),
还有另一种方法是MainAxisAlignment.spaceBetween
用于您的行小部件。我建议使用第二种方法来解决您的问题
推荐阅读
- java - org.springframework.batch.item.ItemStreamException:无法在 JdbcPagingItemReader 中初始化阅读器
- google-analytics - 将 Google Analytics 跟踪脚本添加到 gmail 签名
- nginx - proxy_pass return redirect in nginx
- c# - 如果区域操作系统是泰语,如何保留日期输入的公历日期格式
- node.js - sequelize transaction 中的 setShooter 是什么?
- c - 在 Linux 上创建自定义服务以通过串行 UART 与调制解调器通信
- typescript - 打字稿类型任意数量的通用字段
- reactjs - 如何修复 `...theme.mixins` 意外的 Token SyntaxError?
- testing - 使用 Jest 的 material-ui Dialog 组件测试问题
- angularjs - AngularJS ui-router 如何确定应用程序的根 url?