如何更改FlutterTextButton高度?
这是输出:
- 我尝试制作一个应用程序,但是当我使用 时
TextButton,我得到了两个按钮之间的空间 - 我需要一张一张没有空间
- 如果我使用
Expanded小部件,ScrollChildView则不起作用 - 我尝试但我无法清除这些东西。
- 我尝试制作这种类型的
TextButton.
任何人都知道或对此有任何想法?
import "package:flutter/material.dart";
import 'package:audioplayers/audio_cache.dart';
class Account extends StatefulWidget {
Account({Key key}) : super(key: key);
@override
_AccountState createState() => _AccountState();
}
class _AccountState extends State<Account> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
child: Stack(
children: [
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextButton(
child: Container(
child: Text(
'One',
style: TextStyle(color: Colors.white, fontSize: 10),
),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.red),
),
onPressed: () {
final player = AudioCache();
player.play('note1.wav');
},
),
SizedBox(
height: 1,
),
TextButton(
child: Container(
child: Text(
'Two',
style: TextStyle(color: Colors.white, fontSize: 10),
),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.green),
),
onPressed: () {
final player = AudioCache();
player.play('note2.wav');
},
),
TextButton(
child: Container(
child: Text(
'Three',
style: TextStyle(color: Colors.white, fontSize: 10),
),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.blue),
),
onPressed: () {
final player = AudioCache();
player.play('note3.wav');
},
),
TextButton(
child: Container(
child: Text(
'Four',
style: TextStyle(color: Colors.white, fontSize: 10),
),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.grey),
),
onPressed: () {
final player = AudioCache();
player.play('note4.wav');
},
),
TextButton(
child: Container(
child: Text(
'Five',
style: TextStyle(color: Colors.white, fontSize: 10),
),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.purple),
),
onPressed: () {
final player = AudioCache();
player.play('note5.wav');
},
),
],
),
),
],
),
),
),
);
}
}
回答
您只需用 包裹文本按钮SizedBox并按如下方式设置高度和宽度:
SizedBox(
height: 30,
width: 150,
child: TextButton(...),
)
回答
这可能不会直接回答您的问题,但 aTextButton是一个常规小部件,其width和height可以通过将其包装在SizedBox提供严格约束的a 中进行设置。从这里
match_parent (全屏宽度):
SizedBox(
width: double.infinity, // <-- match_parent
child: TextButton(...)
)
具体宽度:
SizedBox(
width: 100, // <-- Your width
child: TextButton(...)
)