我发现无法在扑动中设置提升按钮的宽度。如果我已经很好地理解了,我应该把提升按钮放入大小框中。然后,我将能够设置框的宽度或高度。正确吗?还有别的办法吗?
在每个按钮周围创建一个大小框有点乏味,所以我想知道为什么他们选择这样做。我很确定他们这么做有一个很好的理由,但我不这么认为。
对于初学者来说,脚手架很难阅读和构建。
new SizedBox(
width: 200.0,
height: 100.0,
child: ElevatedButton(
child: Text('Blabla blablablablablablabla bla bla bla'),
onPressed: _onButtonPressed,
),
),
您不需要使用其他小部件来设置大小。你可以为ElevatedButton使用minimumSize
ElevatedButton(
style: ElevatedButton.styleFrom(
minimumSize: const Size(200, 50),
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50), // <-- Radius
),
),
onPressed: (){},
child: const Text("Text", style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500),),
),
我喜欢的方法来提高按钮与匹配父是包装它与容器。
下面是示例代码。
Container(
width: double.infinity,
child: RaisedButton(
onPressed: () {},
color: Colors.deepPurpleAccent[100],
child: Text(
"Continue",
style: TextStyle(color: Colors.white),
),
),
)
您需要使用扩展小部件。但是,如果按钮位于列上,则Expanded Widget将填充列的其余部分。因此,您需要将Expanded Widget包含在一行中。
Row(children: <Widget>[
Expanded(
flex: 1,
child: RaisedButton(
child: Text("Your Text"),
onPressed: _submitForm,
),
),),])
新按钮TextButton, ElevatedButton, OutlinedButton等将以不同的方式改变。
我从这篇文章中发现了一种方法:你需要“收紧”按钮周围的约束框。
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Kindacode.com'),
),
body: Center(
child: ConstrainedBox(
constraints: BoxConstraints.tightFor(width: 300, height: 200),
child: ElevatedButton(
child: Text('300 x 200'),
onPressed: () {},
),
),
));
}