sticky_float_button

A Flutter implementation of sticky float button.

Getting started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  sticky_float_button:

In your library add the following import:

import 'package:sticky_float_button/sticky_float_button.dart';

For help getting started with Flutter, view the online documentation.

Example

You can use 'Stack' to be located under 'Body' it.

 import 'package:flutter/material.dart';
 import 'package:sticky_float_button/sticky_float_button.dart';
 
 void main() {
   runApp(const MyApp());
 }
 
 class MyApp extends StatelessWidget {
   const MyApp({Key? key}) : super(key: key);
 
   @override
   Widget build(BuildContext context) {
     return MaterialApp(
       title: 'Flutter Sticky Float Button',
       theme: ThemeData(
         primarySwatch: Colors.blue,
       ),
       home: const StickyFloatExample(),
     );
   }
 }
 
 class StickyFloatExample extends StatefulWidget {
   const StickyFloatExample({Key? key}) : super(key: key);
 
   @override
   _StickyFloatExampleState createState() => _StickyFloatExampleState();
 }
 
 class _StickyFloatExampleState extends State<StickyFloatExample> {
   final StickyFloatButtonController _controller =
       StickyFloatButtonController(initPosition: Alignment.topRight);
 
   AppBar _appBar() {
     return AppBar(
       title: const Text("Sticky Float Example"),
     );
   }
 
   Widget _body() {
     return Center(
       child: GestureDetector(
           onTap: () {
             _controller.jumpToPosition(Alignment.center);
           },
           child: const Text("Sticky")),
     );
   }
 
   Widget _floatButton() {
     return StickyFloatButton(
       controller: _controller,
       child: const SingleFloatButton(
         child: CircleAvatar(
           backgroundColor: Colors.grey,
           child: Icon(
             Icons.add,
             color: Colors.white,
           ),
         ),
       ),
     );
   }
 
   @override
   Widget build(BuildContext context) {
     return Scaffold(
       appBar: _appBar(),
       body: Builder(
         builder: (context) {
           return Stack(
             children: [
               _body(),
               _floatButton(),
             ],
           );
         },
       ),
     );
   }
 }

You can find more examples in the Example project.