gpt4 book ai didi

Flutter TextButton 占据整个宽度

转载 作者:行者123 更新时间:2023-12-04 12:36:26 39 4
gpt4 key购买 nike

我正在做一个 TextButton,我需要在页面的右侧部分。
按钮内容在右侧,但按钮本身占据了页面的整个宽度。我怎样才能让它不呢?
这是我的代码:

Padding(
padding: const EdgeInsets.only(bottom: 14.0, right: 7.0),
child: TextButton(
onPressed: onPressed,
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.pressed))
return Theme.of(context).colorScheme.primary.withOpacity(0.5);
return Colors.red;
},
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 9.5, top: 1.6),
child: Icon(Icons.back_arrow, color: Colors.blue),
),
Text( "Home",
style: Theme.of(context)
.textTheme
.bodyText2
.merge(TextStyle(color: Colors.blue)
)
),
]),
),
);
我尝试将按钮包裹在 Align 中,但没有用

最佳答案

不确定您想要实现什么,但是您可以将所有内容都包装到 Row 和 Container 中...

Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: 150,
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () {},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.pressed)) return Theme.of(context).colorScheme.primary.withOpacity(0.5);
return Colors.red; // Use the component's default.
},
),
),
child: Row(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 9.5, top: 1.6),
child: Icon(Icons.arrow_back, color: Colors.blue),
),
Text("Home", style: Theme.of(context).textTheme.bodyText2.merge(TextStyle(color: Colors.blue))),
]),
),
)
],
),
按钮的新对齐方式:
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
height: 50,
width: 150,
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () {},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.pressed)) return Theme.of(context).colorScheme.primary.withOpacity(0.5);
return Colors.red; // Use the component's default.
},
),
),
child: Row(children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 9.5, top: 1.6),
child: Icon(Icons.arrow_back, color: Colors.blue),
),
Text("Home", style: Theme.of(context).textTheme.bodyText2.merge(TextStyle(color: Colors.blue))),
]),
),
)
],
),

关于Flutter TextButton 占据整个宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64380359/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com