I try to show floating button on list view long press, but floating button is not shown.
Any ideas why?
I use the following code:
return GestureDetector(
onLongPress: () {
print('test');
FloatingActionButton.extended(
onPressed: () {
print('test1');
},
icon: const Icon(Icons.add),
label: const Text('Usuń'),
);
2
Answers
@Illusion is right: in order to display the button, it needs to be in the Widget tree.
Here’s an example of a working Flutter app that shows the button on a long-press:
I copied the example code from
FloatingActionButton
documentation and modified a bit to allow showing/hiding the FAB, this should give you some idea. The key points are to putFloatingActionButton
inScaffold
‘sfloatingActionButton
field and use some logic (I use basicsetState
here) to show/hide the FAB based on abool
.