mirror of
https://github.com/vleeuwenmenno/supplements.git
synced 2025-09-11 18:29:12 +02:00
feat: Integrate ShadSonner for improved toast notifications across multiple screens
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../models/ingredient.dart';
|
||||
@@ -571,10 +572,17 @@ class _AddSupplementScreenState extends State<AddSupplementScreen> {
|
||||
.toList();
|
||||
|
||||
if (validIngredients.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content:
|
||||
Text('Please add at least one ingredient with name and amount'),
|
||||
final sonner = ShadSonner.of(context);
|
||||
final id = DateTime.now().millisecondsSinceEpoch;
|
||||
sonner.show(
|
||||
ShadToast(
|
||||
id: id,
|
||||
title: const Text('Please add at least one ingredient with name and amount'),
|
||||
action: ShadButton(
|
||||
size: ShadButtonSize.sm,
|
||||
child: const Text('Dismiss'),
|
||||
onPressed: () => sonner.hide(id),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
@@ -611,21 +619,36 @@ class _AddSupplementScreenState extends State<AddSupplementScreen> {
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(widget.supplement != null
|
||||
final sonner = ShadSonner.of(context);
|
||||
final id = DateTime.now().millisecondsSinceEpoch;
|
||||
sonner.show(
|
||||
ShadToast(
|
||||
id: id,
|
||||
title: Text(widget.supplement != null
|
||||
? 'Supplement updated successfully!'
|
||||
: 'Supplement added successfully!'),
|
||||
backgroundColor: Colors.green,
|
||||
action: ShadButton(
|
||||
size: ShadButtonSize.sm,
|
||||
child: const Text('Dismiss'),
|
||||
onPressed: () => sonner.hide(id),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Error: ${e.toString()}'),
|
||||
backgroundColor: Colors.red,
|
||||
final sonner = ShadSonner.of(context);
|
||||
final id = DateTime.now().millisecondsSinceEpoch;
|
||||
sonner.show(
|
||||
ShadToast(
|
||||
id: id,
|
||||
title: const Text('Error'),
|
||||
description: Text('${e.toString()}'),
|
||||
action: ShadButton(
|
||||
size: ShadButtonSize.sm,
|
||||
child: const Text('Dismiss'),
|
||||
onPressed: () => sonner.hide(id),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user