
我試圖在 TextButton 中左對齊“添加附件”,使其與“開始”和“結束”對齊。
Container(
height: 50,
width: 350,
margin: const EdgeInsets.only(left: 20.0, right: 20.0),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10.0)),
child: TextButton(
child: const Align(
child: Text(
'Add attachment...',
style: TextStyle(color: CupertinoColors.activeBlue, fontSize: 16),
textAlign: TextAlign.left
),
),
onPressed: () {},
)
),
我嘗試添加textAlign: TextAlign.left到 TextButton 但它不起作用。我懷疑 TextButton 沒有占據容器的整個寬度。
uj5u.com熱心網友回復:
你可以使用這個:

TextButton(
// if you are not set the alignment, by default it will align center
child: const Align(
alignment: Alignment.centerLeft,
child: Text('Add attachment...',
style: TextStyle(color: Colors.blue, fontSize: 16),
textAlign: TextAlign.left),
),
onPressed: () {},
),
您也可以使用容器中的 alignmnet。結果是一樣的
Container(
height: 50,
width: 350,
alignment: Alignment.centerLeft,
margin: const EdgeInsets.only(left: 20.0, right: 20.0),
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(10.0)),
child: TextButton(
child: Text('Add attachment...',
style: TextStyle(color: Colors.blue, fontSize: 16),
textAlign: TextAlign.left),
onPressed: () {},
),
);
uj5u.com熱心網友回復:
在容器中添加 alignment: Alignment.centerleft,
uj5u.com熱心網友回復:
基本上,您可以洗掉 text-align 并將其替換為您的文本小部件,然后添加對齊:對齊。center-left 到您的容器,對于按下功能,您可以使用 GestureDetector 小部件包裝容器。
所以代碼如下:
GestureDetector(
onTap: (){},
child: Container(
height: 50,
width: 350,
margin: const EdgeInsets.only(left: 20.0, right: 20.0),
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(10.0)),
alignment: Alignment.centerLeft,
child: Text(
'Add attachment...',
style: TextStyle(color: CupertinoColors.activeBlue, fontSize: 16),
),
),
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/524352.html
標籤:扑镖
