Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Make Two Floating Action Button in Flutter?

Created counter app with one floating action button.

If i want to add one more button for reset the counter, where can i add second floating action button at bottom bar?

Also i have to add any method in void section or is there any reset counter function available?

import 'package:flutter/material.dart';  void main() => runApp(MyApp());  class MyApp extends StatelessWidget {   @override   Widget build(BuildContext context) {     return MaterialApp(       title: 'Counter App',       theme: ThemeData(         primarySwatch: Colors.blue,       ),       home: MyHomePage(title: 'Counter App'),     );   } }  class MyHomePage extends StatefulWidget {   MyHomePage({Key key, this.title}) : super(key: key);    final String title;    @override   _MyHomePageState createState() => _MyHomePageState(); }  class _MyHomePageState extends State<MyHomePage> {   int _counter = 0;   @override   Widget build(BuildContext context) {     return Scaffold(       appBar: AppBar(         title: Text(widget.title),       ),       body: Center(         child: Text('You have pressed the button $_counter times.'),       ),       bottomNavigationBar: BottomAppBar(         child: Container(           height: 50.0,         ),       ),       floatingActionButton: FloatingActionButton(         onPressed: () => setState(() {           _counter++;             }),         tooltip: 'Increment Counter',         child: Icon(Icons.add),       ),       floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,     );   } } 
like image 518
fluttertalk Avatar asked Mar 14 '19 15:03

fluttertalk


People also ask

Can I add two floating action button in Flutter?

Use Wrap() widget to add multiple floating action buttons.

How do I make two buttons in one line in Flutter?

Answer Row( mainAxisAlignment: MainAxisAlignment. spaceEvenly, children: <Widget>[ IconButton( icon: const Icon(Icons. edit), onPressed: () {}, ), FloatingActionButton( child: const Icon(Icons. add), onPressed: () async { Navigator.

How can I show a floating button over all pages in Flutter?

1 Answer. Show activity on this post. You can extract the scaffold as a layout that contains a bottom sheet, and use this layout in every page you build, passing in the title, body, etc., so that the bottom sheet is persistent in all pages.


1 Answers

floatingActionButton property on Scaffold widget do not need to take FloatingActionButton widget necessarily. It can also take Column or Row widgets.

Below, I'm sharing my Scaffold widget example with two floating action buttons on top of each other.

return Scaffold(   appBar: AppBar(     title: Text(""),   ),   body: SingleChildScrollView(/*...*/),   floatingActionButton: Column(     mainAxisAlignment: MainAxisAlignment.end,     children: [       FloatingActionButton(         child: Icon(           Icons.delete         ),         onPressed: () {           //...         },         heroTag: null,       ),       SizedBox(         height: 10,       ),       FloatingActionButton(                    child: Icon(           Icons.star         ),         onPressed: () => _someFunc(),         heroTag: null,       )     ]   ) ); 
like image 136
RaZzLe Avatar answered Sep 21 '22 18:09

RaZzLe