gpt4 book ai didi

Flutter,如何摆脱 raisedButton 底部边距?

转载 作者:IT王子 更新时间:2023-10-29 06:55:41 35 4
gpt4 key购买 nike

所以我试图移除 raisedButton 的底部边距,这样它看起来就好像与它下面的卡片合并了一样。这是它的样子here

这是我的代码

Expanded(
child: Card(
elevation: 5,
// shape:
// RoundedRectangleBorder(borderRadius: BorderRadius.circular(22)),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Apakah anak sudah bisa ... ?",
style: TextStyle(fontWeight: FontWeight.bold)),
),
],
),
Row(
children: <Widget>[
Expanded(
child: RaisedButton(
child: Text(
"Iya",
style: TextStyle(color: Colors.white),
),
color: Colors.green[300],
onPressed: () {}),
),
Expanded(
child: RaisedButton(
child: Text(
"Tidak",
style: TextStyle(color: Colors.white),
),
color: Colors.red[200],
onPressed: () {}))
],
)
],
),
),
)

或者你们有任何其他替代解决方案来实现这一目标吗?

最佳答案

您可以显式设置您的 Row高度匹配你的高度 RaisedButton .只需将它包裹在 Container 中并添加 height 属性。

如果需要,您可以使用 Theme.of(context).buttonTheme.height 访问默认高度。 Theme.of返回当前上下文中使用的 ThemeData

这里是一个最小的例子:

Demo

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Container(
child: Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('Test'),
Container(
height: Theme.of(context).buttonTheme.height,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
RaisedButton(
onPressed: () {},
child: Text('Yes'),
color: Colors.green,
),
RaisedButton(
onPressed: (){},
child: Text('No'),
color: Colors.red,
)
],
),
),
],
)
),
),
)),
);
}
}

关于Flutter,如何摆脱 raisedButton 底部边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57655486/

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