【发布时间】:2021-01-03 20:37:15
【问题描述】:
我的按钮必须在中心,但必须在同一行对齐, 侧面按钮中的文本也应该左对齐。 为此我使用 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),
),
],
),
),
)
],
),
),
);
}
}
【问题讨论】:
-
不确定您要的是什么,但
MaterialButton有一个默认的padding,可以通过在MaterialButton中使用padding: EdgeInsets.zero来删除它。 -
我询问了 Material 按钮里面的文字,应该是左对齐。为此我使用 textAlign: TextAlign.left 但不起作用,您可以在屏幕截图中看到。
-
那是因为
MaterialButton有默认的padding,你可以通过将padding设置为EdgeInsets.zero来移除EdgeInsets.zero。 -
你需要所有按钮在中心垂直和水平对齐吗?
-
i.ibb.co/W2pF5nP/image.png ->image 1 或 i.ibb.co/hZ60zYt/image.png =>image 2 你指的是哪个
标签: android flutter dart flutter-layout