简体   繁体   English

如何在 flutter 中长按列表视图显示浮动操作按钮

[英]How to display a floating action button on long pressing a listview in flutter

I am creating an app that should contain a list on long pressing a list item the floating action button should be displayed on bottom of screen我正在创建一个应包含长按列表项的列表的应用程序,浮动操作按钮应显示在屏幕底部

Wrap you list item with GestureDetector it has a property called onLongPress .You can keep a bool value set to false and onLongPress set the bool to true and show the floating action button.GestureDetector包装你的列表项,它有一个名为onLongPress的属性。你可以将 bool 值设置为 false,onLongPress 将 bool 设置为 true 并显示浮动操作按钮。

#Edit1 declare a bool, #Edit1 声明一个布尔值,

bool showFab = false;

your FAB你的FAB

floatingActionButton: showFab ? FloatingActionButton(...) : SizedBox(),

Your listtile你的清单

GestureDetector(
    onLongPress: () {
      setState((){
showFab = true;
})
    },
    child: YourListWidget(),
  )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM