2

Extended FAB

How would you center the extended FAB provided in Flutter like the Material design spec?

Here the extended FAB is right aligned:

new Scaffold(
    floatingActionButton: new FloatingActionButton.extended(
        onTap: () => {},
        label: new Text('See all results')
    }
)
S.D.
  • 5,197
  • 9
  • 38
  • 64

1 Answers1

5

All you need to do is set the floatingActionButtonLocation property on Scaffold

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: ...       
      body: ...
      floatingActionButton: MyFloatingActionButton(),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat
    );
  }

class MyFloatingActionButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FloatingActionButton.extended(
          icon: Icon(Icons.plus_one),
          onPressed: () => {},
          label: new Text('See all results'));
  }
}

Just note this is a duplicate of the question: Flutter - FloatingActionButton in the center

Mo Meshkani
  • 1,556
  • 2
  • 18
  • 27