flutter Dismissible 可以在拖动时隐藏的widget
import 'package:flutter/material.dart'; class DismissedAppPage extends StatefulWidget { @override State<StatefulWidget> createState() { return new _DismissedAppPageState(); } } class _DismissedAppPageState extends State<DismissedAppPage> { List<String> list = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L' ]; @override Widget build(BuildContext context) { // TODO: implement build return new Scaffold( appBar: new AppBar( title: new Text('Dismissed 学习'), centerTitle: true, ), body: new ListView.builder( itemCount: list.length, itemBuilder: (context, index) { final String curItem = list[index]; return new Dismissible( key: new Key(curItem), direction: DismissDirection.endToStart, onDismissed: (direction) { list.removeAt(index); print("$curItem 被划走了"); final snackBar = new SnackBar(content: new Text("$curItem")); Scaffold.of(context).showSnackBar(snackBar); }, background: new Container( child: new Center( child: new Text('即将被删除'), ), color: Colors.red), child: new ListTile( title: new Text(curItem), )); }), ); } } class DismissedPage extends StatelessWidget { @override Widget build(BuildContext context) { // TODO: implement build return new Scaffold( body: new DismissedAppPage(), ); } }
最后,关注【码上加油站】微信公众号后,有疑惑有问题想加油的小伙伴可以码上加入社群,让我们一起码上加油吧!!!