How to add Floating action Button in Bottom Navigation Bar in Center with border?

前端 未结 2 875
感动是毒
感动是毒 2021-02-10 01:27

I am trying to add a Floating Action Button in the middle of the Bottom Navigation bar. Problem is border is not appearing and also margin in Floating Action Button and icons no

相关标签:
2条回答
  • 2021-02-10 02:13

    Here is a crystal clear official demonstration : https://youtu.be/2uaoEDOgk_I

    Code will be something like this:

    Scaffold(..
      floatingActionButton..
      bottomNavigationBar..
        floatingActionButtonLocation: FloatingActionButtonLocation.endDocked
    
    0 讨论(0)
  • 2021-02-10 02:19

    There are many possible solutions, one of them is to add padding and border.

    import 'package:charts_flutter/flutter.dart' as prefix0;
    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: Scaffold(
            backgroundColor: Colors.blueAccent,
            floatingActionButton: Padding(
              padding: EdgeInsets.only(top: 20),
              child: SizedBox(
                height: 70,
                width: 70,
                child: FloatingActionButton(
                  backgroundColor: Colors.transparent,
                  elevation: 0,
                  onPressed: () {},
                  child: Container(
                    height: 70,
                    width: 70,
                    decoration: BoxDecoration(
                      border: Border.all(color: Colors.white, width: 4),
                      shape: BoxShape.circle,
                      gradient: LinearGradient(
                        begin: const Alignment(0.7, -0.5),
                        end: const Alignment(0.6, 0.5),
                        colors: [
                          Color(0xFF53a78c),
                          Color(0xFF70d88b),
                        ],
                      ),
                    ),
                    child: Icon(Icons.photo_camera, size: 30),
                  ),
                ),
              ),
            ),
            floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
            bottomNavigationBar: BottomAppBar(
              color: Colors.white,
              child: Container(
                height: 80,
                color: Colors.white,
              ),
            ),
          ),
        );
      }
    }
    
    0 讨论(0)
提交回复
热议问题