2026-04-05-maplibra succsess for all and add navigation paage

This commit is contained in:
Hamza-Ayed
2026-04-05 02:50:22 +03:00
parent 8d5fefc9e3
commit 4d5800ff9b
11 changed files with 3512 additions and 1306 deletions

View File

@@ -1,547 +1,292 @@
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'dart:ui';
import '../../constant/colors.dart';
class SnackbarConfig {
static const duration = Duration(seconds: 4);
static const animationDuration = Duration(milliseconds: 400);
static const margin = EdgeInsets.symmetric(horizontal: 16, vertical: 12);
static const borderRadius = 16.0;
static const elevation = 0.0; // تقليل الارتفاع لأننا سنستخدم تأثيرات زجاجية
// ─────────────────────────────────────────────────────────────────────────────
// Snackbar variant definition
// ─────────────────────────────────────────────────────────────────────────────
enum _SnackVariant { success, error, info, warning }
// تأثير زجاجي
static const double blurStrength = 15.0;
static const double opacity = 0.85;
extension _VariantProps on _SnackVariant {
Color get baseColor => switch (this) {
_SnackVariant.success => const Color(0xFF1A9E5C),
_SnackVariant.error => const Color(0xFFD93025),
_SnackVariant.info => const Color(0xFF1A73E8),
_SnackVariant.warning => const Color(0xFFF29900),
};
// حدود شفافة
static final Border glassBorder = Border.all(
color: Colors.white.withOpacity(0.25),
width: 1.5,
);
Color get surfaceColor => switch (this) {
_SnackVariant.success => const Color(0xFFF0FBF5),
_SnackVariant.error => const Color(0xFFFEF2F1),
_SnackVariant.info => const Color(0xFFF0F6FF),
_SnackVariant.warning => const Color(0xFFFFF8E6),
};
// ظل أكثر نعومة وانتشار
static final List<BoxShadow> shadows = [
BoxShadow(
color: Colors.black.withOpacity(0.15),
blurRadius: 12,
spreadRadius: 1,
offset: const Offset(0, 4),
),
BoxShadow(
color: Colors.black.withOpacity(0.08),
blurRadius: 20,
spreadRadius: 0,
offset: const Offset(0, 2),
),
];
IconData get icon => switch (this) {
_SnackVariant.success => Icons.check_circle_rounded,
_SnackVariant.error => Icons.error_rounded,
_SnackVariant.info => Icons.info_rounded,
_SnackVariant.warning => Icons.warning_amber_rounded,
};
String get label => switch (this) {
_SnackVariant.success => 'Success',
_SnackVariant.error => 'Error',
_SnackVariant.info => 'Info',
_SnackVariant.warning => 'Warning',
};
HapticFeedbackType get haptic => switch (this) {
_SnackVariant.error => HapticFeedbackType.medium,
_SnackVariant.warning => HapticFeedbackType.medium,
_SnackVariant.success => HapticFeedbackType.light,
_SnackVariant.info => HapticFeedbackType.selection,
};
}
// تطبيق تأثير زجاجي باستخدام Container مخصص
class GlassSnackbar extends StatelessWidget {
final Color baseColor;
final Widget child;
enum HapticFeedbackType { light, medium, selection }
const GlassSnackbar({
required this.baseColor,
required this.child,
Key? key,
}) : super(key: key);
// ─────────────────────────────────────────────────────────────────────────────
// Core snackbar widget
// ─────────────────────────────────────────────────────────────────────────────
class _SnackContent extends StatefulWidget {
final String message;
final _SnackVariant variant;
const _SnackContent({required this.message, required this.variant});
@override
State<_SnackContent> createState() => _SnackContentState();
}
class _SnackContentState extends State<_SnackContent>
with TickerProviderStateMixin {
late final AnimationController _ctrl;
late final Animation<double> _scaleAnim;
late final Animation<double> _progressAnim;
static const Duration _displayDuration = Duration(seconds: 4);
@override
void initState() {
super.initState();
_ctrl = AnimationController(vsync: this, duration: _displayDuration);
_scaleAnim = CurvedAnimation(
parent: AnimationController(
vsync: this,
duration: const Duration(milliseconds: 500),
)..forward(),
curve: Curves.elasticOut,
);
_progressAnim = Tween<double>(begin: 1.0, end: 0.0).animate(
CurvedAnimation(parent: _ctrl, curve: Curves.linear),
);
_ctrl.forward();
}
@override
void dispose() {
_ctrl.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(SnackbarConfig.borderRadius),
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: SnackbarConfig.blurStrength,
sigmaY: SnackbarConfig.blurStrength,
),
child: Container(
decoration: BoxDecoration(
color: baseColor.withOpacity(SnackbarConfig.opacity),
borderRadius: BorderRadius.circular(SnackbarConfig.borderRadius),
border: SnackbarConfig.glassBorder,
boxShadow: SnackbarConfig.shadows,
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
baseColor.withOpacity(SnackbarConfig.opacity + 0.05),
baseColor.withOpacity(SnackbarConfig.opacity - 0.05),
],
),
final v = widget.variant;
final accent = v.baseColor;
final surface = v.surfaceColor;
return Container(
margin: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
decoration: BoxDecoration(
color: surface,
borderRadius: BorderRadius.circular(18),
border: Border.all(color: accent.withOpacity(0.18), width: 1.2),
boxShadow: [
BoxShadow(
color: accent.withOpacity(0.12),
blurRadius: 20,
spreadRadius: -2,
offset: const Offset(0, 6),
),
child: child,
BoxShadow(
color: Colors.black.withOpacity(0.06),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(18),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// ── Main row ──────────────────────────────────────────────────
Padding(
padding: const EdgeInsets.fromLTRB(14, 14, 10, 12),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Animated icon badge
ScaleTransition(
scale: _scaleAnim,
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: accent.withOpacity(0.12),
shape: BoxShape.circle,
),
child: Icon(v.icon, color: accent, size: 22),
),
),
const SizedBox(width: 12),
// Text content
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
v.label.tr,
style: TextStyle(
color: accent,
fontSize: 13,
fontWeight: FontWeight.w700,
letterSpacing: 0.2,
),
),
const SizedBox(height: 3),
Text(
widget.message,
style: TextStyle(
color: Colors.grey[800],
fontSize: 13.5,
height: 1.4,
fontWeight: FontWeight.w400,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
),
// Close button
GestureDetector(
onTap: () {
HapticFeedback.lightImpact();
Get.closeCurrentSnackbar();
},
child: Container(
width: 30,
height: 30,
margin: const EdgeInsets.only(left: 6),
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(
Icons.close_rounded,
size: 16,
color: Colors.grey[500],
),
),
),
],
),
),
// ── Thin progress strip ───────────────────────────────────────
AnimatedBuilder(
animation: _progressAnim,
builder: (_, __) => Stack(
children: [
// Track
Container(
height: 3,
color: accent.withOpacity(0.08),
),
// Fill
FractionallySizedBox(
widthFactor: _progressAnim.value,
child: Container(
height: 3,
decoration: BoxDecoration(
color: accent.withOpacity(0.45),
borderRadius: const BorderRadius.only(
topRight: Radius.circular(4),
bottomRight: Radius.circular(4),
),
),
),
),
],
),
),
],
),
),
);
}
}
SnackbarController mySnackeBarError(String message) {
// تأثير اهتزاز للأخطاء
HapticFeedback.mediumImpact();
// ─────────────────────────────────────────────────────────────────────────────
// Internal dispatcher — single source of truth
// ─────────────────────────────────────────────────────────────────────────────
SnackbarController _show(_SnackVariant variant, String message) {
// Dismiss any existing snackbar first (no stacking)
if (Get.isSnackbarOpen) Get.closeCurrentSnackbar();
final Color errorBaseColor = AppColor.redColor;
switch (variant.haptic) {
case HapticFeedbackType.light:
HapticFeedback.lightImpact();
case HapticFeedbackType.medium:
HapticFeedback.mediumImpact();
case HapticFeedbackType.selection:
HapticFeedback.selectionClick();
}
return Get.snackbar(
'',
'',
snackPosition: SnackPosition.TOP,
margin: SnackbarConfig.margin,
duration: SnackbarConfig.duration,
animationDuration: SnackbarConfig.animationDuration,
borderRadius: SnackbarConfig.borderRadius,
backgroundColor: Colors.transparent, // شفاف لأننا سنستخدم حاوية مخصصة
barBlur: 0, // إيقاف تشويش الخلفية الافتراضي لأننا سنستخدم BlurFilter
overlayBlur: 1.5,
overlayColor: Colors.black12,
userInputForm: Form(
child: GlassSnackbar(
baseColor: errorBaseColor,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
child: Row(
children: [
// أيقونة متحركة
TweenAnimationBuilder<double>(
tween: Tween(begin: 0.0, end: 1.0),
duration: const Duration(milliseconds: 500),
curve: Curves.elasticOut,
builder: (context, value, child) {
return Transform.scale(
scale: value,
child: child,
);
},
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.25),
shape: BoxShape.circle,
),
child: const Icon(
Icons.error_rounded,
color: Colors.white,
size: 26,
),
),
),
const SizedBox(width: 16),
// محتوى النص
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Error'.tr,
style: const TextStyle(
fontWeight: FontWeight.w700,
color: Colors.white,
fontSize: 16,
letterSpacing: 0.3,
shadows: [
Shadow(
color: Colors.black26,
offset: Offset(0, 1),
blurRadius: 2,
),
],
),
),
const SizedBox(height: 4),
Text(
message,
style: const TextStyle(
color: Colors.white,
fontSize: 14,
height: 1.3,
fontWeight: FontWeight.w400,
),
),
],
),
),
// زر الإغلاق
InkWell(
onTap: () {
HapticFeedback.lightImpact();
Get.closeCurrentSnackbar();
},
child: Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
shape: BoxShape.circle,
),
child: const Icon(
Icons.close_rounded,
color: Colors.white,
size: 18,
),
),
),
],
),
),
),
),
backgroundColor: Colors.transparent,
margin: EdgeInsets.zero,
padding: EdgeInsets.zero,
duration: const Duration(seconds: 4),
animationDuration: const Duration(milliseconds: 380),
barBlur: 0,
overlayBlur: 0,
overlayColor: Colors.transparent,
isDismissible: true,
dismissDirection: DismissDirection.horizontal,
forwardAnimationCurve: Curves.easeOutBack,
dismissDirection: DismissDirection.up,
forwardAnimationCurve: Curves.easeOutCubic,
reverseAnimationCurve: Curves.easeInCubic,
snackStyle: SnackStyle.FLOATING,
userInputForm: Form(
child: _SnackContent(message: message, variant: variant),
),
);
}
SnackbarController mySnackbarSuccess(String message) {
// تأثير اهتزاز للنجاح
HapticFeedback.lightImpact();
// ─────────────────────────────────────────────────────────────────────────────
// Public API — drop-in replacements for the old functions
// ─────────────────────────────────────────────────────────────────────────────
SnackbarController mySnackbarSuccess(String message) =>
_show(_SnackVariant.success, message);
final Color successBaseColor = AppColor.greenColor;
SnackbarController mySnackeBarError(String message) =>
_show(_SnackVariant.error, message);
return Get.snackbar(
'',
'',
snackPosition: SnackPosition.TOP,
margin: SnackbarConfig.margin,
duration: SnackbarConfig.duration,
animationDuration: SnackbarConfig.animationDuration,
borderRadius: SnackbarConfig.borderRadius,
backgroundColor: Colors.transparent, // شفاف لأننا سنستخدم حاوية مخصصة
barBlur: 0, // إيقاف تشويش الخلفية الافتراضي لأننا سنستخدم BlurFilter
overlayBlur: 1.5,
overlayColor: Colors.black12,
userInputForm: Form(
child: GlassSnackbar(
baseColor: successBaseColor,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
child: Row(
children: [
// أيقونة متحركة
TweenAnimationBuilder<double>(
tween: Tween(begin: 0.0, end: 1.0),
duration: const Duration(milliseconds: 600),
curve: Curves.elasticOut,
builder: (context, value, child) {
return Transform.scale(
scale: value,
child: child,
);
},
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.25),
shape: BoxShape.circle,
),
child: const Icon(
Icons.check_circle_rounded,
color: Colors.white,
size: 26,
),
),
),
const SizedBox(width: 16),
// محتوى النص
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Success'.tr,
style: const TextStyle(
fontWeight: FontWeight.w700,
color: Colors.white,
fontSize: 16,
letterSpacing: 0.3,
shadows: [
Shadow(
color: Colors.black26,
offset: Offset(0, 1),
blurRadius: 2,
),
],
),
),
const SizedBox(height: 4),
Text(
message,
style: const TextStyle(
color: Colors.white,
fontSize: 14,
height: 1.3,
fontWeight: FontWeight.w400,
),
),
],
),
),
// زر الإغلاق
InkWell(
onTap: () {
HapticFeedback.lightImpact();
Get.closeCurrentSnackbar();
},
child: Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
shape: BoxShape.circle,
),
child: const Icon(
Icons.close_rounded,
color: Colors.white,
size: 18,
),
),
),
],
),
),
),
),
isDismissible: true,
dismissDirection: DismissDirection.horizontal,
forwardAnimationCurve: Curves.easeOutBack,
reverseAnimationCurve: Curves.easeInCubic,
);
}
SnackbarController mySnackbarInfo(String message) =>
_show(_SnackVariant.info, message);
// إضافة: دالة للمعلومات والتنبيهات
SnackbarController mySnackbarInfo(String message) {
// تأثير اهتزاز خفيف
HapticFeedback.selectionClick();
final Color infoBaseColor = Colors.blue;
return Get.snackbar(
'',
'',
snackPosition: SnackPosition.TOP,
margin: SnackbarConfig.margin,
duration: SnackbarConfig.duration,
animationDuration: SnackbarConfig.animationDuration,
borderRadius: SnackbarConfig.borderRadius,
backgroundColor: Colors.transparent, // شفاف لأننا سنستخدم حاوية مخصصة
barBlur: 0, // إيقاف تشويش الخلفية الافتراضي لأننا سنستخدم BlurFilter
overlayBlur: 1.5,
overlayColor: Colors.black12,
userInputForm: Form(
child: GlassSnackbar(
baseColor: infoBaseColor,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
child: Row(
children: [
// أيقونة متحركة
TweenAnimationBuilder<double>(
tween: Tween(begin: 0.0, end: 1.0),
duration: const Duration(milliseconds: 500),
curve: Curves.elasticOut,
builder: (context, value, child) {
return Transform.scale(
scale: value,
child: child,
);
},
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.25),
shape: BoxShape.circle,
),
child: const Icon(
Icons.info_rounded,
color: Colors.white,
size: 26,
),
),
),
const SizedBox(width: 16),
// محتوى النص
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Info'.tr,
style: const TextStyle(
fontWeight: FontWeight.w700,
color: Colors.white,
fontSize: 16,
letterSpacing: 0.3,
shadows: [
Shadow(
color: Colors.black26,
offset: Offset(0, 1),
blurRadius: 2,
),
],
),
),
const SizedBox(height: 4),
Text(
message,
style: const TextStyle(
color: Colors.white,
fontSize: 14,
height: 1.3,
fontWeight: FontWeight.w400,
),
),
],
),
),
// زر الإغلاق
InkWell(
onTap: () {
HapticFeedback.lightImpact();
Get.closeCurrentSnackbar();
},
child: Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
shape: BoxShape.circle,
),
child: const Icon(
Icons.close_rounded,
color: Colors.white,
size: 18,
),
),
),
],
),
),
),
),
isDismissible: true,
dismissDirection: DismissDirection.horizontal,
forwardAnimationCurve: Curves.easeOutBack,
reverseAnimationCurve: Curves.easeInCubic,
);
}
// إضافة: دالة للتحذيرات
SnackbarController mySnackbarWarning(String message) {
// تأثير اهتزاز متوسط
HapticFeedback.mediumImpact();
final Color warningBaseColor = Colors.orange;
return Get.snackbar(
'',
'',
snackPosition: SnackPosition.TOP,
margin: SnackbarConfig.margin,
duration: SnackbarConfig.duration,
animationDuration: SnackbarConfig.animationDuration,
borderRadius: SnackbarConfig.borderRadius,
backgroundColor: Colors.transparent, // شفاف لأننا سنستخدم حاوية مخصصة
barBlur: 0, // إيقاف تشويش الخلفية الافتراضي لأننا سنستخدم BlurFilter
overlayBlur: 1.5,
overlayColor: Colors.black12,
userInputForm: Form(
child: GlassSnackbar(
baseColor: warningBaseColor,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
child: Row(
children: [
// أيقونة متحركة
TweenAnimationBuilder<double>(
tween: Tween(begin: 0.0, end: 1.0),
duration: const Duration(milliseconds: 500),
curve: Curves.elasticOut,
builder: (context, value, child) {
return Transform.scale(
scale: value,
child: child,
);
},
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.25),
shape: BoxShape.circle,
),
child: const Icon(
Icons.warning_rounded,
color: Colors.white,
size: 26,
),
),
),
const SizedBox(width: 16),
// محتوى النص
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Warning'.tr,
style: const TextStyle(
fontWeight: FontWeight.w700,
color: Colors.white,
fontSize: 16,
letterSpacing: 0.3,
shadows: [
Shadow(
color: Colors.black26,
offset: Offset(0, 1),
blurRadius: 2,
),
],
),
),
const SizedBox(height: 4),
Text(
message,
style: const TextStyle(
color: Colors.white,
fontSize: 14,
height: 1.3,
fontWeight: FontWeight.w400,
),
),
],
),
),
// زر الإغلاق
InkWell(
onTap: () {
HapticFeedback.lightImpact();
Get.closeCurrentSnackbar();
},
child: Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
shape: BoxShape.circle,
),
child: const Icon(
Icons.close_rounded,
color: Colors.white,
size: 18,
),
),
),
],
),
),
),
),
isDismissible: true,
dismissDirection: DismissDirection.horizontal,
forwardAnimationCurve: Curves.easeOutBack,
reverseAnimationCurve: Curves.easeInCubic,
);
}
SnackbarController mySnackbarWarning(String message) =>
_show(_SnackVariant.warning, message);