Flutter Dismissible 滑动删除示例

import 'package:flutter/material.dart';
void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget{
  List items = new List.generate(30, (i) => "列表项${i+1}");
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("dd"),
        ),
        body:ListView.builder(
            itemBuilder: (context, index)
            {
              final item = items[index];
              return Dismissible(
                key: Key(item),
                onDismissed: (direction){
                  items.removeAt(index);
                  Scaffold.of(context).showSnackBar(
                    new SnackBar(content: new Text("$item 被删除了"))
                  );
                },
                child: ListTile(
                  title: Text("$item"),
                ),
              );
            }
        )
      ),
    );
  }
}

效果图如下:

Flutter Dismissible 滑动删除示例_第1张图片

 

你可能感兴趣的:(Flutter)