19

When using FloatingActionButton in conjunction with a ListView, it hides part of the UI of the ListView entries, as seen in the screenshot.
Is there a way to automatically add extra spacing at the bottom of a ListView so that the + button does not hide any content?

enter image description here

2
  • Then there will be completely empty space at your bottom, let say you FAB is of size 60, then from the bottom whole 60 is empty which is even weirder. Jul 12, 2019 at 7:26
  • you can move the FAB, a little to the left so it does not hide the buttons, or end the listView at the end of the FAB
    – key
    Jul 12, 2019 at 8:17

2 Answers 2

35

Assuming you are using ListView, there is a very nice and simple solution to this.
You probably do not want to add padding around the ListView itself as that would make some area of your UI unused.

ListView has apadding parameter for exactly this use case. You can essentially add some padding to the bottom of your ListView that is part of the scrollable area. This means that you will only start seeing this padding once you have scrolled all the way to the bottom. This will allow you to drag the last few items above the FloatingActionButton.
To find an appropriate value for the padding, you can make use of kFloatingActionButtonMargin and _kExtendedSizeConstraints, which is not accessible, thus, I will just use 48 like this.

This means that you will want to add the following to your ListView:

ListView(
  padding: const EdgeInsets.only(bottom: kFloatingActionButtonMargin + 48),
  ..
)

Here is a working example:

import 'package:flutter/material.dart';

main() {
  runApp(MaterialApp(
      home: Scaffold(
    body: ListView.builder(
        padding: const EdgeInsets.only(bottom: kFloatingActionButtonMargin + 48),
        itemCount: 23,
        itemBuilder: (context, index) => ListTile(
              trailing: Text('$index'),
            )),
    floatingActionButton: FloatingActionButton(
      onPressed: () {},
    ),
  )));
}

screen capture

1
1

Expandable( ListView.builder( ... padding: EdgeInsets.only(bottom: 200), ... ) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.