gpt4 book ai didi

android - 如何对齐左按钮(位于中心小部件内)中的文本 flutter ?

转载 作者:行者123 更新时间:2023-12-03 02:52:06 26 4
gpt4 key购买 nike

我的按钮必须位于中心,但必须在同一行上对齐,
侧面按钮中的文字也应左对齐。
为此,我使用textalign left但在我的代码中不起作用,我不知道为什么。 This is my layout screenshot.
因此,任何人都可以修改我的代码,以使按钮内的文本向左对齐,而不影响我的按钮位置。
谢谢

class Something extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Solve Before Downvote !'),
),
body: Container(
color: Color(0xff263238),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SingleChildScrollView(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MaterialButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
padding: EdgeInsets.only(left: 5),
color: Colors.green,
onPressed: () {},
child: Text('SomeThing', textAlign: TextAlign.left),
),
MaterialButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
color: Colors.green,
onPressed: () { },
child: Text('Nothing', textAlign: TextAlign.left),
),
MaterialButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
color: Colors.green,
onPressed: () {},
child: Text('Can You do something ?',
textAlign: TextAlign.left),
),
MaterialButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
color: Colors.green,
onPressed: () {},
child: Text('Nothing to do !', textAlign: TextAlign.left),
),
],
),
),
)
],
),
),
);
}
}

what i made

最佳答案

请检查以下代码。我已经用代码注释掉了解决方案。

class Something extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Solve Before Downvote !'),
),
body: Container(
width: MediaQuery.of(context).size.width,
color: Color(0xff263238),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SingleChildScrollView(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(2.0),
child: Material(
color: Colors.green,
borderRadius: BorderRadius.circular(10.0),
child: InkWell(
onTap: () {
setState(() {
abc = true;
});
},
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 12, 15, 12),
child: Text('SomeThing', textAlign: TextAlign.left),
),
),
),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: Material(
color: Colors.green,
borderRadius: BorderRadius.circular(10.0),
child: InkWell(
onTap: () {
setState(() {
abc = true;
});
},
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 12, 15, 12),
child: Text('Nothing', textAlign: TextAlign.left),
),
),
),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: Material(
color: Colors.green,
borderRadius: BorderRadius.circular(10.0),
child: InkWell(
onTap: () {
setState(() {
abc = true;
});
},
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 12, 15, 12),
child: Text('Can You do something ?',
textAlign: TextAlign.left),
),
),
),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: Material(
color: Colors.green,
borderRadius: BorderRadius.circular(10.0),
child: InkWell(
onTap: () {
setState(() {
abc = true;
});
},
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 12, 15, 12),
child: Text('Nothing to do !',
textAlign: TextAlign.left),
),
),
),
),
],
),
),
)
],
),
),
);
}
}

关于android - 如何对齐左按钮(位于中心小部件内)中的文本 flutter ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63929770/

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