Floating Action Button, fab, is an important component of the material design user interface. It is a circular button which usually floats above the right bottom of the screen. A fab is used for triggering actions such as create, edit, etc.
Following is the simple floating action button in flutter example:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: Text('Floating Action Button Example'),
),
body: Center(
child: Text('See the fab!')
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// Add your onPressed code here!
},
child: Icon(Icons.add),
backgroundColor: Colors.blue,
),
),
);
}
}
The output is as given below:

You can also use extended floating action button in flutter. In such fab, you can add label also. see the example of extended floating action button below:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: Text('Extended Floating Action Button Example'),
),
body: Center(
child: Text('See the fab!')
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
// Add your onPressed code here!
},
icon: Icon(Icons.add),
label: Text('Add'),
backgroundColor: Colors.blue,
),
),
);
}
}
Output:

That’s how you add floating action button in flutter.