我有一个具有ListView和Floating Button的应用程序。如果要显示ListView中的索引0,我想隐藏浮动按钮,而当ListView中没有显示索引0时,我要显示浮动按钮。网络中的大多数信息(包括Stackoverflow)都涉及在滚动(方向)时隐藏按钮,而不是基于ListView显示的索引。
答案 0 :(得分:0)
您可以核对清单是否为空。我只是添加了一个演示代码。
List<String> demoList = new List<>();
floatingActionButton: demoList != null ?
FloatingActionButton(
onPressed: () {
// Add your onPressed code here!
},
child: Icon(Icons.navigation),
backgroundColor: Colors.green,
)
:Text(''),
);
如果列表中有一个值,则显示一个浮动按钮。
答案 1 :(得分:0)
在FloatingActionButton周围使用“可见性”小部件。当该项显示时,只需调用具有可见性值的setState()方法即可。