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, ); } }
Use Wrap() widget to add multiple floating action buttons.
Answer Row( mainAxisAlignment: MainAxisAlignment. spaceEvenly, children: <Widget>[ IconButton( icon: const Icon(Icons. edit), onPressed: () {}, ), FloatingActionButton( child: const Icon(Icons. add), onPressed: () async { Navigator.
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.
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, ) ] ) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With