ListView Dismissible (ListView Swipe) In Flutter

ListView Dismissible (ListView Swipe) In Flutter :

Screenshot :

ListView Dismissible (ListView Swipe) In Flutter
import 'package:flutter/material.dart';

void main() {
  runApp(new MaterialApp(
    title: 'Flutter Tutorial',
    home: new FlutterListViewDismissible(),
  ));
}

class FlutterListViewDismissible extends StatefulWidget {
  FlutterListViewDismissible() : super();

  @override
  FlutterListViewDismissibleState createState() =>
      FlutterListViewDismissibleState();
}

class FlutterListViewDismissibleState
    extends State<FlutterListViewDismissible> {
  GlobalKey<ScaffoldState> _key = GlobalKey(); // added
  List<String> topicList = new List<String>();

  @override
  Widget build(BuildContext context) {
    topicList.add('Flutter');
    topicList.add("Flutter Tutorial");
    topicList.add("Flutter ListView Delete");
    topicList.add("Flutter ListView Swipe to Delete");
    topicList.add("Flutter ListView Delete to Undo");
    topicList.add("Flutter ListView Dismissible color change");

    return Scaffold(
        key: _key,
        appBar: AppBar(title: Text("ListView Swipe To Delete - Undo")),
        body: ListView.builder(
            itemCount: topicList.length,
            itemBuilder: (context, index) {
              return Dismissible(
                  //SWIPE TO DELETE
                  key: Key(topicList[index]),
                  child: ListTile(title: Text(topicList[index])),
                  //background: Container(color: Colors.grey),
                  onDismissed: (direction) {
                    setState(() {
                      // added this block
                      String delete = topicList.removeAt(index);
                      _key.currentState
                        ..removeCurrentSnackBar()
                        ..showSnackBar(SnackBar(
                            content: Text("DELETEs \"$delete\""),
                            action: SnackBarAction(
                                label: "UNDO",
                                onPressed: () => setState(
                                      () => topicList.insert(index, delete),
                                    ) // this is what you needed
                                )));
                    });
                  });
            }));
  }
}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in