gpt4 book ai didi

flutter - 关闭小部件时如何将 : Remove separator from ListView. 分开?

转载 作者:行者123 更新时间:2023-12-03 08:23:43 25 4
gpt4 key购买 nike

我正在使用 ListView.separated 构建一个 Dismissible 小部件列表,但是当其中一个小部件被关闭时,分隔符不会消失。

小部件关闭时如何删除分隔符?

最佳答案

在此示例中,分隔符已成功删除

final items = List<String>.generate(20, (i) => "Item ${i + 1}");

@override
Widget build(BuildContext context) {
final title = 'Dismissing Items';

return MaterialApp(
title: title,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text(title),
),
body: ListView.separated(
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index];

return Dismissible(
// Each Dismissible must contain a Key. Keys allow Flutter to
// uniquely identify widgets.
key: Key(item),
// Provide a function that tells the app
// what to do after an item has been swiped away.
onDismissed: (direction) {
// Remove the item from the data source.
setState(() {
items.removeAt(index);
});

// Then show a snackbar.
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text("$item dismissed")));
},
// Show a red background as the item is swiped away.
background: Container(color: Colors.red),
child: ListTile(title: Text('$item')),
);
},
separatorBuilder: (BuildContext context, int index) => Divider(),
),
),
);
}

关于flutter - 关闭小部件时如何将 : Remove separator from ListView. 分开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67125280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com