Flutter中基于Sqflite动态生成删除按钮并实现指定数据删除的问题
Flutter Sqflite删除按钮功能实现
我想要实现删除按钮功能,让用户可以删除自己选中查看的对应数据。
如下图所示,Sqflite中每新增一条数据,页面上就会对应新增一个删除按钮:
- 仅有1条数据时的页面效果:

- 存在多条数据时的页面效果:

以下是我当前实现删除功能及页面构建的代码:
FutureBuilder( future: DatabaseHelper.instance.getCards(), builder: (BuildContext context, AsyncSnapshot<List<Cards>> snapshot) { return SizedBox( width: 40.w, child: Column( children: snapshot.data!.map((cards) { return SizedBox( width: 40.w, child: RaisedButton( color: Color(0xffBE4E49), textColor: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10)), onPressed: () async { // null; setState(() { DatabaseHelper.instance.remove(cards.id!); }); Navigator.pushAndRemoveUntil( context, MaterialPageRoute( builder: (_) => new HomeScreen()), (Route<dynamic> route) => false, ); }, child: Text( 'DELETE', style: TextStyle( fontSize: 13.sp, fontWeight: FontWeight.w700, fontFamily: 'Poppins'), ), ), ); }).toList(), ), ); }),
内容的提问来源于stack exchange,提问作者Caramel
相关产品推荐
相关产品推荐

