flutter Dismissible 可以在拖动时隐藏的widget
Posted loaderman
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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(), );
以上是关于flutter Dismissible 可以在拖动时隐藏的widget的主要内容,如果未能解决你的问题,请参考以下文章
Flutter 在尝试使用 Dismissible ListView 删除 futurebuilder 中的项目时出现范围错误
Flutter:Dismissible 小部件内的 SnackBar 无法正常工作
Flutter Dismissible 小部件,带有 confirmDismiss 和 showAlertDialog 停止应用程序