HendrickV9
HendrickV9

Reputation: 21

Flutter move floatingActionButton

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: {}

Upvotes: 0

Views: 179

Answers (2)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63829

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
    );
  }
}

Upvotes: 0

Gustavo Scarpini
Gustavo Scarpini

Reputation: 11

Wrap your FloatingActionButton inside a Padding, like that:

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

Upvotes: 1

Related Questions