ionic-planb-logistic-app-fl.../lib/utils/toast_helper.dart
Mathias Beaulieu-Duncan edb106a7fd Refactor theme system and remove unused platforms
- Overhaul theme system with Svrnty design and WCAG AAA compliance
- Remove android, macos, and web platform files (iOS-only focus)
- Update components with improved dark mode map and UI refinements
- Enhance settings page with additional configuration options
- Add theme system documentation in lib/theme/README.md
- Update CLAUDE.md with comprehensive theme guidelines

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 14:47:51 -05:00

85 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
class ToastHelper {
static void showSuccess(
BuildContext context,
String message, {
Duration duration = const Duration(seconds: 3),
}) {
_showToast(
context,
message,
duration: duration,
backgroundColor: Colors.green,
);
}
static void showError(
BuildContext context,
String message, {
Duration duration = const Duration(seconds: 5),
}) {
_showToast(
context,
message,
duration: duration,
backgroundColor: Colors.red,
);
}
static void showInfo(
BuildContext context,
String message, {
Duration duration = const Duration(seconds: 3),
}) {
_showToast(
context,
message,
duration: duration,
);
}
static void _showToast(
BuildContext context,
String message, {
required Duration duration,
Color? backgroundColor,
}) {
final screenWidth = MediaQuery.of(context).size.width;
final screenHeight = MediaQuery.of(context).size.height;
final topPadding = MediaQuery.of(context).padding.top;
final bottomPadding = MediaQuery.of(context).padding.bottom;
final toastWidth = screenWidth * 0.5; // 50% of screen width
final horizontalMargin = (screenWidth - toastWidth) / 2;
// Position toast at top with safe padding
final topMargin = topPadding + 10;
const toastHeight = 60.0;
final bottomMargin = screenHeight - topMargin - toastHeight;
// Ensure bottom margin is at least the safe area padding
final safeBottomMargin = bottomMargin > bottomPadding ? bottomMargin : bottomPadding + 10;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
message,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
duration: duration,
behavior: SnackBarBehavior.floating,
backgroundColor: backgroundColor,
margin: EdgeInsets.only(
top: topMargin,
left: horizontalMargin,
right: horizontalMargin,
bottom: safeBottomMargin,
),
),
);
}
}