我有一个应用程序,它有一个ListView和Floating Button。如果ListView中显示了索引0,我想隐藏浮动按钮,而当ListView中没有显示索引0时,我想显示浮动按钮。web中的大多数信息(包括Stackoverflow(涵盖了滚动时隐藏按钮(方向(,而不是基于ListView显示的索引。
您可以检查表是否为null。我只是添加了一个演示代码。
List<String> demoList = new List<>();
floatingActionButton: demoList != null ?
FloatingActionButton(
onPressed: () {
// Add your onPressed code here!
},
child: Icon(Icons.navigation),
backgroundColor: Colors.green,
)
:Text(''),
);
如果列表有一个值,那么它会显示一个浮动按钮。
围绕FloatingActionButton使用可见性小部件。当项目显示时,只需调用具有可见性值的setState((方法。