
我想將我的孩子與標題的元素對齊。如果標題的第一個元素可以開始靠近邊緣,那就太好了。
此外,如您所見,標題只有 5 個元素,所以我放了一個 SizedBox 來留出空間,但您有更好的解決方案嗎?
class Test extends StatelessWidget {
const Test({Key? key}) : super(key: key);
Widget _listItem(index) {
return Container(
padding: const EdgeInsets.all(10),
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [
Text("Test"),
Text('Test'),
Text('Test'),
Text('Test'),
Text('Test'),
Icon(
Icons.create_outlined,
color: Colors.grey,
size: 36.0,
),
],)
);
}
@override
Widget build(BuildContext context) {
List L = [1,2,3,4];
return Scaffold(
appBar: AppBar(
title: Text('Test'),
),
body:
Padding(
padding: const EdgeInsets.all(50),
child:
Column(
children: [
Container(
color: Colors.blue,
height: 50,
child: Row(mainAxisAlignment: MainAxisAlignment.spaceAround,children: const [
Text('Test',style: TextStyle(color: Colors.white)),
Text('Test',style: TextStyle(color: Colors.white)),
Text('Test',style: TextStyle(color: Colors.white)),
Text('Test',style: TextStyle(color: Colors.white)),
Text('Test',style: TextStyle(color: Colors.white)),
SizedBox(width: 30),
],),
),
Expanded(
child:
ListView.separated(
separatorBuilder: (context, index) {
return const Divider(thickness: 1, color: Colors.blue);
},
itemCount: L.length,
itemBuilder: (_, index) {
return _listItem(index);
}),
),
],
)
)
);
}
}
uj5u.com熱心網友回復:
您可以用小部件包裹行的孩子Expanded,因此每個人都將獲得相同的寬度。
Widget _listItem(index) {
return Container(
// padding: const EdgeInsets.all(10),
child: Row(
children: const [
Text("Test"),
Text('Test'),
Text('Test'),
Text('Test'),
Text('Test'),
Icon(
Icons.create_outlined,
color: Colors.grey,
size: 36.0,
),
].map((e) => Expanded(child: e)).toList(),
));
}
其他人也是如此。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/490212.html
