列中 RaisedButton 小部件之间出现不需要的空间 [英] Unwanted space appearing between RaisedButton widgets in a column
问题描述
tl;dr 为什么我没有明确设置两个按钮之间会出现空格?
我正在尝试制作如下布局:
I am trying to make a layout like the one below:
但是,两个按钮之间出现了大约 16 像素的空间,我不知道它是从哪里来的.
However, what appears to be about 16px of space appears between the two buttons and I cannot figure out where it is coming from.
我起初认为可能是 Column
正在添加空间,但我使用的是不应添加任何空间的 MainAxisAlignment.center
.我现在认为可能有一些 Material 主题会自动将填充应用于 RaisedButton
,但是我已经查看了两个 button_theme.dart 和 raised_button.dart 似乎只设置了内部填充(文本和按钮边缘之间).我确信我忽略了一些东西,如果能帮助我找出这个空间存在的原因,我将不胜感激.
I at first thought maybe the Column
was adding space but I am using MainAxisAlignment.center
which shouldn't add any. I now think that there is perhaps some Material theming going on that automatically applies padding to the RaisedButton
, however I have looked through both button_theme.dart and raised_button.dart and it seemed like only the inner padding (between text and button edges) was being set. I'm sure I overlooked something and would appreciate any help in finding out why this space exists.
auth.dart(图片中显示的屏幕)
...
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(flex: 2, child: Container()),
Expanded(
flex: 8,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 32),
child: Image(
fit: BoxFit.contain,
image: AssetImage('lib/res/drawable/logo.webp'))),
PrimaryButton(
onPressed: //...,
child: Text('Log In')),
PrimaryButton(
onPressed: //...,
child: Text('Sign Up')),
])),
Expanded(flex: 2, child: Container()),
]));
}
primary_button.dart(扩展 RaisedButton
的自定义圆形按钮小部件):
primary_button.dart (custom rounded button widget that extends RaisedButton
):
...
Widget build(BuildContext context) {
return Theme(
data: Theme.of(context).copyWith(
textTheme: Theme.of(context).textTheme,
buttonTheme: Theme.of(context).buttonTheme.copyWith(
padding: EdgeInsets.all(0),
minWidth: double.infinity,
buttonColor: Theme.of(context).accentColor,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24))),
),
child: Builder(builder: super.build));
}
推荐答案
添加属性 materialTapTargetSize
并将其设置为 MaterialTapTargetSize.shrinkWrap
.
add the property materialTapTargetSize
and set it to MaterialTapTargetSize.shrinkWrap
.
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
如果您检查 RawMaterialButton
的源代码,它会根据该值添加一个填充:
if you check the source code of RawMaterialButton
it adds a padding based on that value:
Size minSize;
switch (widget.materialTapTargetSize) {
case MaterialTapTargetSize.padded:
minSize = const Size(48.0, 48.0);
break;
case MaterialTapTargetSize.shrinkWrap:
minSize = Size.zero;
break;
}
return Semantics(
container: true,
button: true,
enabled: widget.enabled,
child: _InputPadding(
minSize: minSize,
child: result,
),
);
这篇关于列中 RaisedButton 小部件之间出现不需要的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!