'showing 1 data from Sqlflite flutter
So i want to make a delete button, so the user could delete those data according to the data they choose to see.
Each time the data on the sqflite were added the delete button increase shown here on the picture
Heres the picture when theres only 1 data
and here's the picture when they got more than 1 data
Here's My code on how the delete work and the Code of how they were build
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(),
),
);
}),
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|