Selectable List View In Flutter
This article will help, if you are developing a flutter application that needs to select the list items, like in a chat-app to delete the selected chats, or in a todo-app to remove or tick the selected todos.
Find the updated article here.
STEP 1: Place your ListView inside a Stateful Widget
This step is although not necessary if you are using some state managements other than setState() like Bloc, or Provider.
I have chosen the setState() state management with Stateful Widget for simplicity.
class SelectListItem extends StatefulWidget{
@override
_SelectListItemState createState() => _SelectListItemState();
}
class _SelectListItemState extends State<SelectListItem>{
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text(‘Select List Items’)),
body: ListView()
}
STEP 2: Add items to your ListView
Here I’m using the ListView builder (instead of ListView above) to generate list-items for…