Flutter:为提升的按钮添加边框
在 Flutter 中,您可以使用ElevatedButton.styleFrom() 静态方法为提升按钮添加边框(并自定义其粗细和颜色),如下所示:
ElevatedButton(
style: ElevatedButton.styleFrom(
side: const BorderSide(
width: 2, // the thickness
color: Colors.black // the color of the border
)
),
/* ... */
),
如果您需要创建圆形边框,请使用以下实现:
ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
side: const BorderSide(
width: 8, // thickness
color: Colors.deepPurple // color
),
// border radius
borderRadius: BorderRadius.circular(16)
)
),
/* ... */
),
让我们检查下面的具体示例以更清楚。
代码:
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Button One (a rectangular button)
ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
side: const BorderSide(width: 2, color: Colors.black),
primary: Colors.amber,
padding:
const EdgeInsets.symmetric(vertical: 10, horizontal: 30)),
child: const Text(
'Button One',
style: TextStyle(color: Colors.black, fontSize: 20),
),
),
const SizedBox(
height: 30,
),
// Button Two (a pill button)
ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
side: const BorderSide(width: 5, color: Colors.red),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30)),
primary: Colors.black,
padding:
const EdgeInsets.symmetric(vertical: 20, horizontal: 50)),
child: const Text(
'Button Two',
style: TextStyle(fontSize: 20, color: Colors.white),
),
),
const SizedBox(
height: 30,
),
// Button Three (a rounded button)
ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
side:
const BorderSide(width: 8, color: Colors.deepPurple),
borderRadius: BorderRadius.circular(16)),
primary: Colors.orangeAccent,
padding:
const EdgeInsets.symmetric(vertical: 20, horizontal: 80)),
child: const Text(
'Button Three',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.deepPurple),
),
),
],
),
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布,任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站。本站所有源码与软件均为原作者提供,仅供学习和研究使用。如您对本站的相关版权有任何异议,或者认为侵犯了您的合法权益,请及时通知我们处理。