本文主要是介绍Flutter-listview的item左右滑动,删除item,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import 'package:flutter/material.dart';//列表左右滑动删除 void main() =>runApp(MaterialApp(home: HomePage(),));class HomePage extends StatelessWidget {final List<String> items = List.generate(20, (index) => 'item $index');@overrideWidget build(BuildContext context) {return Scaffold(body: ListView.builder(itemCount: items.length,itemBuilder: (context, index) {final item = items[index];return Dismissible(onDismissed: (_) {//参数暂时没有用到,则用下划线表示print("--removeAt---" + index.toString());items.removeAt(index);},// 监听movementDuration: Duration(milliseconds: 100),key: Key(item),child: ListTile(title: Text('$item'),),background: Container(color: Color(0xffff0000),),);},),);} }
这篇关于Flutter-listview的item左右滑动,删除item的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!