Refactor and enhance UI components across multiple screens

- Updated date and time formatting in debug notifications screen for clarity.
- Wrapped context-dependent state updates in post-frame callbacks in history screen to ensure proper context usage.
- Improved layout and styling in settings screen by reordering radio list tiles.
- Enhanced logging in auto sync service for better error tracking.
- Added context mounted checks in notification router to prevent errors during navigation.
- Updated bulk take dialog to use new UI components from shadcn_ui package.
- Refactored take supplement dialog to utilize shadcn_ui for a more modern look and feel.
- Adjusted info chip and supplement card widgets to use updated color schemes and layouts.
- Updated pubspec.yaml and pubspec.lock to include new dependencies and versions.
This commit is contained in:
2025-08-31 19:15:32 +02:00
parent 6a2085f4e6
commit 666008f05d
15 changed files with 597 additions and 423 deletions

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import '../models/supplement.dart';
import '../providers/supplement_provider.dart';
@@ -56,10 +57,10 @@ class _SupplementCardState extends State<SupplementCard> {
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: isCompletelyTaken
? Theme.of(context).colorScheme.surface
: isTakenToday
? Theme.of(context).colorScheme.secondaryContainer
: Theme.of(context).colorScheme.surface,
? Theme.of(context).colorScheme.surface
: isTakenToday
? Theme.of(context).colorScheme.secondaryContainer
: Theme.of(context).colorScheme.surface,
border: Border.all(
color: isCompletelyTaken
? Colors.green.shade600
@@ -176,24 +177,6 @@ class _SupplementCardState extends State<SupplementCard> {
),
),
),
ElevatedButton(
onPressed: widget.onTake,
style: ElevatedButton.styleFrom(
backgroundColor: isCompletelyTaken
? Colors.green.shade500
: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.inverseSurface,
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
minimumSize: const Size(60, 32),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(
isCompletelyTaken ? '' : 'Take',
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w600),
),
),
],
],
],
@@ -223,18 +206,17 @@ class _SupplementCardState extends State<SupplementCard> {
}
},
itemBuilder: (context) => [
if (isTakenToday)
PopupMenuItem(
value: 'take',
onTap: widget.onTake,
child: const Row(
children: [
Icon(Icons.add_circle_outline),
SizedBox(width: 8),
Text('Take Again'),
],
),
PopupMenuItem(
value: 'take',
onTap: widget.onTake,
child: Row(
children: [
Icon(isTakenToday ? Icons.add_circle_outline : Icons.medication),
const SizedBox(width: 8),
Text(isTakenToday ? 'Take Again' : 'Take'),
],
),
),
const PopupMenuItem(
value: 'edit',
child: Row(
@@ -325,7 +307,7 @@ class _SupplementCardState extends State<SupplementCard> {
children: todayIntakes.map((intake) {
final units = intake['units'] as double;
final unitsText = units == 1.0
? '${widget.supplement.unitType}'
? widget.supplement.unitType
: '${units.toStringAsFixed(units % 1 == 0 ? 0 : 1)} ${widget.supplement.unitType}';
return Container(
@@ -356,49 +338,38 @@ class _SupplementCardState extends State<SupplementCard> {
],
// Ingredients section
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant.withValues(alpha: 0.3),
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Ingredients per ${widget.supplement.unitType}:',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Theme.of(context).colorScheme.onSurfaceVariant,
ShadCard(
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Ingredients per ${widget.supplement.unitType}:',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: ShadTheme.of(context).colorScheme.foreground,
),
),
),
const SizedBox(height: 8),
Wrap(
spacing: 8,
runSpacing: 4,
children: widget.supplement.ingredients.map((ingredient) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: Theme.of(context).colorScheme.primary.withValues(alpha: 0.3),
const SizedBox(height: 8),
Wrap(
spacing: 8,
runSpacing: 4,
children: widget.supplement.ingredients.map((ingredient) {
return ShadBadge(
child: Text(
'${ingredient.name} ${ingredient.amount}${ingredient.unit}',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w500,
),
),
),
child: Text(
'${ingredient.name} ${ingredient.amount}${ingredient.unit}',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.primary,
),
),
);
}).toList(),
),
],
);
}).toList(),
),
],
),
),
),
@@ -408,18 +379,34 @@ class _SupplementCardState extends State<SupplementCard> {
Row(
children: [
Expanded(
child: _InfoChip(
icon: Icons.schedule,
label: '${widget.supplement.frequencyPerDay}x daily',
context: context,
child: ShadBadge(
child: Row(
children: [
Icon(
Icons.schedule,
size: 14,
color: ShadTheme.of(context).colorScheme.foreground,
),
const SizedBox(width: 4),
Text('${widget.supplement.frequencyPerDay}x daily'),
],
),
),
),
const SizedBox(width: 8),
Expanded(
child: _InfoChip(
icon: Icons.medication,
label: '${widget.supplement.numberOfUnits} ${widget.supplement.unitType}',
context: context,
child: ShadBadge(
child: Row(
children: [
Icon(
Icons.medication,
size: 14,
color: ShadTheme.of(context).colorScheme.foreground,
),
const SizedBox(width: 4),
Text('${widget.supplement.numberOfUnits} ${widget.supplement.unitType}'),
],
),
),
),
],
@@ -427,66 +414,43 @@ class _SupplementCardState extends State<SupplementCard> {
if (widget.supplement.reminderTimes.isNotEmpty) ...[
const SizedBox(height: 8),
_InfoChip(
icon: Icons.notifications,
label: 'Reminders: ${widget.supplement.reminderTimes.join(', ')}',
context: context,
fullWidth: true,
ShadBadge(
child: Row(
children: [
Icon(
Icons.notifications,
size: 14,
color: ShadTheme.of(context).colorScheme.foreground,
),
const SizedBox(width: 4),
Expanded(
child: Text(
'Reminders: ${widget.supplement.reminderTimes.join(', ')}',
overflow: TextOverflow.ellipsis,
),
),
],
),
),
],
if (widget.supplement.notes != null && widget.supplement.notes!.isNotEmpty) ...[
const SizedBox(height: 8),
Container(
width: double.infinity,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant.withValues(alpha: 0.2),
borderRadius: BorderRadius.circular(8),
),
child: Text(
widget.supplement.notes!,
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontStyle: FontStyle.italic,
ShadCard(
child: Padding(
padding: const EdgeInsets.all(8),
child: Text(
widget.supplement.notes!,
style: TextStyle(
fontSize: 12,
color: ShadTheme.of(context).colorScheme.foreground,
fontStyle: FontStyle.italic,
),
),
),
),
],
const SizedBox(height: 16),
// Take button
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: widget.onTake,
icon: Icon(
isCompletelyTaken ? Icons.check_circle : Icons.medication,
size: 18,
),
label: Text(
isCompletelyTaken
? 'All doses taken today'
: isTakenToday
? 'Take next dose'
: 'Take supplement',
style: const TextStyle(fontWeight: FontWeight.w600),
),
style: ElevatedButton.styleFrom(
backgroundColor: isCompletelyTaken
? Colors.green.shade500
: Theme.of(context).colorScheme.primary,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
elevation: isCompletelyTaken ? 0 : 2,
),
),
),
],
),
),
@@ -516,7 +480,7 @@ class _InfoChip extends StatelessWidget {
width: fullWidth ? double.infinity : null,
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant.withValues(alpha: 0.4),
color: Theme.of(context).colorScheme.surfaceContainerHighest.withValues(alpha: 0.4),
borderRadius: BorderRadius.circular(8),
),
child: Row(