【发布时间】:2019-03-18 02:32:13
【问题描述】:
我正在尝试将大小设置为FloatingActionButton,我想设置width/height,我的意思是,让按钮变大,我正在寻找一个圆形按钮,但只有一个我得到的是这个,所以,我开始使用这个,但我需要它更大一点。
【问题讨论】:
标签: flutter dart flutter-layout
我正在尝试将大小设置为FloatingActionButton,我想设置width/height,我的意思是,让按钮变大,我正在寻找一个圆形按钮,但只有一个我得到的是这个,所以,我开始使用这个,但我需要它更大一点。
【问题讨论】:
标签: flutter dart flutter-layout
【讨论】:
使用Container 可以指定width 和height,然后使用RawMaterialButton,如下所示:
final myFabButton = Container(
width: 200.0,
height: 200.0,
child: new RawMaterialButton(
shape: new CircleBorder(),
elevation: 0.0,
child: Icon(
Icons.favorite,
color: Colors.blue,
),
onPressed: () {},
),
);
【讨论】:
仅使用 SizedBox 似乎不会在 FAB 内缩放子级。您需要在两者之间使用 FittedBox。
floatingActionButton: SizedBox(
height: 100.0,
width: 100.0,
child: FittedBox(
child: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {},
),
),
),
感谢chemturion 的评论。
请查看 Raouf Rahiche 的answer 了解更多详情。
使用SizedBox
SizedBox(
width: 200.0,
height: 200.0,
child: FloatingActionButton(
onPressed: () {},
),
)
【讨论】:
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked 下也可以使用,谢谢!
小 (40 x 40)
FloatingActionButton.small(
onPressed: onPressed,
child: Icon(Icons.edit),
)
常规 (56 x 56)
FloatingActionButton(
onPressed: onPressed,
child: Icon(Icons.edit),
)
大 (96 x 96)
FloatingActionButton.large(
onPressed: onPressed,
child: Icon(Icons.edit),
)
扩展
FloatingActionButton.extended(
onPressed: onPressed,
label: Text('Extended'),
icon: Icon(Icons.edit),
)
自定义尺寸(A x B):
SizedBox(
width: 20,
height: 20,
child: FittedBox(
child: FloatingActionButton(
onPressed: onPressed,
child: Icon(Icons.edit),
),
),
)
【讨论】:
RawMaterialButton(
elevation: 2.0,
shape: CircleBorder(),
fillColor: Colors.red,
onPressed: (){},
child: Icon(
Icons.add,
color: Colors.white,
size: 20.0,
),
constraints: BoxConstraints.tightFor(
width: 56.0,
height: 56.0,
),
)
通过这种方式..您可以添加任何类型的按钮。
【讨论】:
您可以使用Transform.scale() 小部件包装您的按钮:
floatingActionButton: Transform.scale(
scale: 1.5,
child: FloatingActionButton(onPressed: () {}),
)
【讨论】:
FittedBox 不仅可以缩放,还可以定位孩子。
Transform.scale 是一种相对昂贵的方法
FloatingActionButton 有一个名为 mini 的属性,可以设置为 true。
floatingActionButton: FloatingActionButton(
mini: true,
onPressed: (){
},
child: Icon(Icons.play_arrow_outlined),
),
【讨论】:
这是我在我的一个应用中实现的方式:
floatingActionButton: Container(
height: 100.0,
width: 100.0,
child: FittedBox(
child: FloatingActionButton(
onPressed: _loadProgress,
child: Icon(Icons.ac_unit_outlined),
child: Text(
'Get Joke!',
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.w700, fontSize: 10.0),
),
),
),
),
【讨论】:
https://api.flutter.dev/flutter/material/FloatingActionButton/FloatingActionButton.html
use mini: true
FloatingActionButton(
child: Icon(
Icons.delete
),
onPressed: () {
}, mini: true,
),
【讨论】:
试试这个:
floatingActionButton: Container(
height: 50.0,
width: MediaQuery.of(context).size.width * 0.92,
decoration: BoxDecoration(
color: Colors.blue, borderRadius: BorderRadius.circular(30)),
child: Center(
child: Text(
'SAVE',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 16.0,
color: whiteTextColor),
),
),
),
【讨论】: