Search code examples
androidflutterdartpadding

Flutter || Padding for floatingActionButton in flutter


In my flutter project I used a floatingActionButton and I want to add a padding but I don't know how to make the tree with my code. Any help is highly appreciated.

This is my code :

 floatingActionButton: Visibility(
              visible: buttonshow,
              child: FloatingActionButton(
                onPressed: () {
                  scrollToTop();
                },
                shape: const StadiumBorder(
                    side: BorderSide(
                        color: Color(0xff135888), width: 2.5)),
                backgroundColor: Colors.transparent,
                elevation: 0.0,
                child: const Icon(
                  Icons.keyboard_arrow_up, color: Color(0xff135888),
                  size: 28.0,),
                mini: true,

              ),
            ),

Solution

  • Wrap your Visibility with an Expanded Widget.

    Updated code:

    floatingActionButton: Padding(
      padding: const EdgeInsets.all(8.0),
      child: Visibility(
        visible: buttonshow,
        child: FloatingActionButton(
          onPressed: () {
            scrollToTop();
          },
          shape: const StadiumBorder(
              side: BorderSide(color: Color(0xff135888), width: 2.5)),
          backgroundColor: Colors.transparent,
          elevation: 0.0,
          child: const Icon(
            Icons.keyboard_arrow_up,
            color: Color(0xff135888),
            size: 28.0,
          ),
          mini: true,
        ),
      ),
    ),