In my provider I have defined some logics so that if the user chooses an item twice then I will return and do nothing:
void addCoffee(Coffee coffee) async {
if (state.contains(coffee) == true) {
return;
} else {
final db = await _getDatabase();
await db.insert(
'cart_provider',
{
'id': coffee.id,
'coffeeImage': coffee.coffeeImage,
'CoffeeName': coffee.coffeeName,
'CoffeePrice': coffee.coffeePrice,
},
);
state = [...state, coffee];
}
}
and here in another file I am passing the coffee item to my riverpod provider:
InkWell(
onTap: () {
setState(() {
Navigator.of(context).pop();
ref.read(cartProvider.notifier).addCoffee(widget.coffee);
showDialog(
context: context,
builder: (ctx) {
return AlertDialog(
alignment: Alignment.center,
contentTextStyle: TextStyle(
color: Theme.of(context).colorScheme.primary,
),
content: const Text(
'Successfully added to cart',
style: TextStyle(fontSize: 18),
textAlign: TextAlign.center,
),
);
},
);
});
},
splashColor: const Color.fromARGB(255, 43, 35, 35),
borderRadius: BorderRadius.circular(12),
child: Container(
clipBehavior: Clip.hardEdge,
width: 300,
height: 65,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary,
borderRadius: BorderRadius.circular(12),
),
child: const Text(
'Add to cart',
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
),
),
I really don’t know why it’s not working, since I have started to save data through sqflite
package I have this problem.
I have checked my codes a few times but I can not find the problem.
if you need more information please text me
New contributor
Ehsan Javdan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.