Home > OS >  Flutter move floatingActionButton
Flutter move floatingActionButton

Time:08-03

I have a button that I wanted to move it up, but I can't, is there any way to leave it where I marked it?

enter image description here

This is my code:

floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
        floatingActionButton: FloatingActionButton.extended(
          backgroundColor: const Color(0xff5808fb),
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
          onPressed: randomText,
          label: Text('Novamente'),
          heroTag: {}

CodePudding user response:

Wrap your FloatingActionButton inside a Padding, like that:

  floatingActionButton: Padding(
    padding: EdgeInsets.only(bottom: 100),
    child: FloatingActionButton(
      child: Icon(Icons.add),
      onPressed: () {},
    ),
  )

CodePudding user response:

You can use floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, to get there.

Or to have more control, create a custom class extending FloatingActionButtonLocation .

class MyFabPosition extends FloatingActionButtonLocation {
  @override
 Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) {
    final size = scaffoldGeometry.scaffoldSize;
    return Offset(
      size.width / 2 - 100, // width control
      size.height * .8, // height control
    );
  }
}
  • Related