Search code examples
flutterdartwidgetstatefulwidget

achieve functionality like floating action button in flutter


enter image description here

how can I achieve this functionality with fixed at the bottom, above the list and the list gets scroll in flutter? Thanks in advance!!!


Solution

  • you can use FloatingActionButton.extended() and create Row inside it then wrap your Row with GestureDetector to catch onTap.

    Example:

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(MaterialApp(
        home: MyApp(),
      ));
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text("Floating Action Button Extended"),
          ),
          floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
          floatingActionButton: FloatingActionButton.extended(
            onPressed: () {},
            backgroundColor: Colors.white,
            label: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                GestureDetector(
                  onTap: () {
                    print('button 1');
                  },
                  child: Row(
                    children: [
                      Padding(
                        padding: const EdgeInsets.only(right: 5.0),
                        child: Icon(
                          Icons.verified_user,
                          color: Colors.purple,
                        ),
                      ),
                      Text(
                        'Me',
                        style: TextStyle(
                          fontSize: 15,
                          color: Colors.purple,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ],
                  ),
                ),
                SizedBox(width: 30),
                GestureDetector(
                  onTap: () {
                    print('button 2');
                  },
                  child: Row(
                    children: [
                      Padding(
                        padding: const EdgeInsets.only(right: 5.0),
                        child: Icon(
                          Icons.qr_code,
                          color: Colors.purple,
                        ),
                      ),
                      Text(
                        'Scan',
                        style: TextStyle(
                          fontSize: 15,
                          color: Colors.purple,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        );
      }
    }
    

    result:

    enter image description here