我希望我的行寬固定為某個給定值。但是 Row 正在占用全寬。
我想要如下;

但它的全寬如下:

我嘗試過的:
Card(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.height),
SizedBox(
width: 5,
),
Text(
'Sort',
style: ReediusCustomTheme.lable1
.copyWith(color: ReediusCustomTheme.lableColor1),
),
SizedBox(
width: 24,
),
Text(
'|',
style: ReediusCustomTheme.lable1
.copyWith(color: ReediusCustomTheme.lableColor1),
),
SizedBox(
width: 24,
),
Icon(Icons.filter_alt_outlined),
SizedBox(
width: 5,
),
Text(
'Filter',
style: ReediusCustomTheme.lable1
.copyWith(color: ReediusCustomTheme.lableColor1),
),
],
),
),
uj5u.com熱心網友回復:
這取決于您的卡片在里面 - 例如,只需您的代碼將卡片包裝在例如中心或容器中即可滿足您的需求。
考慮 ”…
小部件不知道也不決定自己在螢屏中的位置,因為決定小部件位置的是小部件的父級。
由于父級的大小和位置反過來也取決于它自己的父級,因此如果不考慮整個樹,就不可能精確地定義任何小部件的大小和位置。
如果孩子想要與其父母不同的尺寸,而父母沒有足夠的資訊來對齊它,那么孩子的尺寸可能會被忽略。
在定義對齊時要具體。
" 來自
uj5u.com熱心網友回復:
您的代碼作業正常。可能您的父小部件不適合您的情況。
如果你在 ListView 小部件中使用它并且你有一個串列來顯示它,你可以試試這個:
Stack(
children: [
Padding(
padding: const EdgeInsets.only(top: 38.0),
child: ListView.builder(
itemCount: 5,
itemBuilder: (BuildContext context, int index) {
return ListTile(
leading: const Icon(Icons.list),
title: Text("List item $index"));
}),
),
Align(
alignment: Alignment.topCenter,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24.0),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: const [
Icon(Icons.height),
SizedBox(
width: 5,
),
Text(
'Sort',
),
SizedBox(
width: 24,
),
SizedBox(
height: 22,
child: VerticalDivider(
thickness: 1,
width: 2,
color: Colors.black,
),
),
SizedBox(
width: 24,
),
Icon(Icons.filter_alt_outlined),
SizedBox(
width: 5,
),
Text(
'Filter',
),
],
),
),
),
),
],
),

uj5u.com熱心網友回復:
用 Container 包裹你的行并為該 Container 提供寬度
容器(寬度:250,孩子:卡片(孩子:行(mainAxisAlignment:MainAxisAlignment.center,mainAxisSize:MainAxisSize.min,孩子:[圖示(圖示高度),SizedBox(寬度:5,),文本('排序',樣式:ReediusCustomTheme.lable1 .copyWith(顏色:ReediusCustomTheme.lableColor1),),SizedBox(寬度:24,),文本('|',樣式:ReediusCustomTheme.lable1 .copyWith(顏色:ReediusCustomTheme.lableColor1),),SizedBox( width: 24, ), Icon(Icons.filter_alt_outlined), SizedBox( width: 5, ), Text( 'Filter', style: ReediusCustomTheme.lable1 .copyWith(color: ReediusCustomTheme.lableColor1), ), ], ), ), ),
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/491023.html
