Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - FloatingActionButton in the center

Is it possible to make the FloatingActionButton in the centre instead of the right side?

import 'package:flutter/material.dart'; import 'number.dart'; import 'keyboard.dart';  class ContaPage extends StatelessWidget {   @override   Widget build(BuildContext context) => new Scaffold(     body: new Column(       children: <Widget>[         new Number(),         new Keyboard(),       ],     ),     floatingActionButton: new FloatingActionButton(       elevation: 0.0,       child: new Icon(Icons.check),       backgroundColor: new Color(0xFFE57373),       onPressed: (){}     )   ); } 

enter image description here

like image 319
rafaelcb21 Avatar asked Jun 23 '17 05:06

rafaelcb21


People also ask

How do you align a floating action button in center in Flutter?

The above examples are great, but if you want to have full control over the exact location of the floating action button, you should wrap your FloatingActionButton widget with Align widget and use Alignment(x axis, y axis) to set the exact location.

How do I turn off the floating action button in Flutter?

How to Disable Button in Flutter. To disable button in Flutter, just assign the null value to the onPressed parameter of the Button.


2 Answers

I don't know if this was added since this question was first answered, but there's now floatingActionButtonLocation property on the Scaffold class.

It would work like this in your original question:

class ContaPage extends StatelessWidget {   @override   Widget build(BuildContext context) => new Scaffold(     // ...      floatingActionButton: new FloatingActionButton(       // ...FloatingActionButton properties...     ),      // Here's the new attribute:      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,   ); } 

Also see the documentation:

  • Scaffold class (search floatingActionButtonLocation): https://docs.flutter.dev/flutter/material/Scaffold-class.html
  • ...and the FloatingActionButtonLocation class: https://docs.flutter.dev/flutter/material/FloatingActionButtonLocation-class.html
like image 85
Brian Kung Avatar answered Oct 15 '22 23:10

Brian Kung


With the new flutter API you do that very easily just change the floatingActionButtonLocation property in the Scaffold to

FloatingActionButtonLocation.centerFloat 

enter image description here

Example :

return new Scaffold(   floatingActionButton: new FloatingActionButton(     child: const Icon(Icons.add),   ),   floatingActionButtonLocation:           FloatingActionButtonLocation.centerFloat,   bottomNavigationBar: new BottomAppBar(     color: Colors.white,     child: new Row(...),   ), ); 
like image 20
Raouf Rahiche Avatar answered Oct 15 '22 23:10

Raouf Rahiche