I have an app that has a ListView and Floating Button. I wanted to hide the Floating Button if Index 0 in the ListView is shown and show the Floating Button when Index 0 is not shown in the ListView. Most of the information in the web (including Stackoverflow) covers hiding the button when scrolling (direction) and not based on the index shown by ListView.
Asked
Active
Viewed 937 times
2 Answers
0
you can checklist null or not. I just add a demo code.
List<String> demoList = new List<>();
floatingActionButton: demoList != null ?
FloatingActionButton(
onPressed: () {
// Add your onPressed code here!
},
child: Icon(Icons.navigation),
backgroundColor: Colors.green,
)
:Text(''),
);
if the list has a value then it shows a floating button.

Kamruzzaman Sajib
- 48
- 1
- 5
-
Thanks for the feedback, in my scenario, the list is actually populated so I wanted to know whether index 0 is shown or has scrolled away from the UI – Calvin Oct 26 '20 at 07:22
-
you can use setState, when your list updated, your main list will be notified – Kamruzzaman Sajib Oct 26 '20 at 07:57
0
Use Visibility widget around FloatingActionButton. When the item shows, just call setState() method with visibility value.

Mahi
- 1,297
- 1
- 14
- 28
-
Thanks for the feedbacks. I have found this widget and apparently it is requested to Flutter Team: https://github.com/flutter/flutter/issues/19941. In the thread, there is a solution proposed: https://pub.dev/packages/widgets_visibility_provider – Calvin Oct 26 '20 at 09:55