Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
wrap your FAB with a
FittedBox
inside a
Container
or
SizedBox
and then change the width and the height of it.
example :
floatingActionButton: Container(
height: 100.0,
width: 100.0,
child: FittedBox(
child: FloatingActionButton(onPressed: () {}),
–
–
Use a Container
where you can specify width
and height
, then use a RawMaterialButton
, like this:
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: () {},
You do not have to reinvent the wheel, flutter team knew it will be needed.
Instead of using regular FloatingActionButton()
use FloatingActionButton.extended()
example code:
FloatingActionButton.extended(
onPressed: () {},
icon: Icon(Icons.save),
label: Text("DOWNLOAD"),
Update
Just using a SizedBox does not seem to scale the child inside the FAB. You need to use a FittedBox in between.
floatingActionButton: SizedBox(
height: 100.0,
width: 100.0,
child: FittedBox(
child: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {},
Thanks chemturion for the comment.
Please checkout Raouf Rahiche's answer for more details.
Old Answer
Use a SizedBox
SizedBox(
width: 200.0,
height: 200.0,
child: FloatingActionButton(
onPressed: () {},
–
–
Most of the answers here using hardcoded values, but actually we have to apply generic solutions here, which should be constant in all the UI.
Scaffold(
floatingActionButton: Container(
height: MediaQuery.of(context).size.width * 0.2,
width: MediaQuery.of(context).size.width * 0.2,
child: FloatingActionButton(onPressed: () {}),
Set width and height using MediaQuery
which will be same across the devices.
Output:
You can wrap your button with a Transform.scale()
widget:
floatingActionButton: Transform.scale(
scale: 1.5,
child: FloatingActionButton(onPressed: () {}),
–
–
This is how I have implemented in one of my apps:
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),
FloatingActionButton has a property called mini which can be set to true.
floatingActionButton: FloatingActionButton(
mini: true,
onPressed: (){
child: Icon(Icons.play_arrow_outlined),
you can use extendedPadding. it works for me
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
// Add your onPressed code here!
extendedPadding:
const EdgeInsets.only(left: 100, right: 100, top: 20, bottom: 20),
label: const Text('Approve'),
icon: const Icon(Icons.thumb_up),
backgroundColor: Colors.pink,
Please use the following option in theme.
floatingActionButtonTheme: const FloatingActionButtonThemeData(
sizeConstraints: BoxConstraints.expand(
width: 60,
height: 60,
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),
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.