اريد ان يتم تفريغ حقل او ادخل مبلغ جديد بعد اضافة المبلغ عبر ايقونة الاضافة
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_savedAmounts.isNotEmpty && amountsController.text.isEmpty) {
amountsController.text = _formatWithThousandsSeparator(_savedAmounts.first);
}
});
code Copy code
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
elevation: 8,
insetPadding: const EdgeInsets.all(20),
child: SingleChildScrollView(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 20),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: BorderRadius.circular(24),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header
Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(
Icons.monetization_on_rounded,
size: 28,
color: Theme.of(context).colorScheme.primary,
),
),
const SizedBox(width: 12),
Text(
'المحفظة الرقمية',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurface,
),
),
],
),
const SizedBox(height: 24),
// Saved Amounts List
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.1),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Theme.of(context).colorScheme.outline.withOpacity(0.1),
),
),
child: _savedAmounts.isEmpty
? Column(
children: [
Icon(
Icons.wallet_rounded,
size: 40,
color: Theme.of(context).colorScheme.primary.withOpacity(0.5),
),
const SizedBox(height: 12),
Text(
'أضف المبالغ التي تريد استخدامها بشكل متكرر',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontSize: 14,
),
textAlign: TextAlign.center,
),
],
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'اختر من المبالغ المحفوظة:',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 12),
SizedBox(
height: 120,
child: ListView.builder(
itemCount: _savedAmounts.length,
itemBuilder: (context, index) {
final amount = _savedAmounts[index];
return ListTile(
contentPadding: EdgeInsets.zero,
leading: Radio<int>(
value: amount,
groupValue: _savedAmounts.first,
onChanged: (value) {
setState(() {
amountsController.text = _formatWithThousandsSeparator(value!);
});
},
),
title: Text(
_formatWithThousandsSeparator(amount),
style: TextStyle(
fontFamily: tajawalFont,
fontWeight: FontWeight.w600,
),
),
trailing: IconButton(
icon: Icon(
Icons.delete_outline,
color: Theme.of(context).colorScheme.error,
),
onPressed: () {
setState(() {
_savedAmounts.remove(amount);
if (_savedAmounts.isNotEmpty) {
amountsController.text =
_formatWithThousandsSeparator(_savedAmounts.first);
} else {
amountsController.clear();
}
});
},
),
);
},
),
),
],
),
),
const SizedBox(height: 20),
// Amount Input Field
TextField(
controller: amountsController,
keyboardType: TextInputType.number,
inputFormatters: [ThousandsSeparatorInputFormatter()],
decoration: InputDecoration(
labelText: 'أو أدخل مبلغًا جديدًا',
labelStyle: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
suffixIcon: IconButton(
icon: Icon(
Icons.add_circle_rounded,
color: Theme.of(context).colorScheme.primary,
size: 28,
),
onPressed: () {
final raw = amountsController.text.replaceAll(',', '');
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
});
amountsController.clear(); // تفريغ الحقل خارج setState
},
),
filled: true,
fillColor: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.1),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: BorderSide.none,
),
),
onSubmitted: (value) {
final raw = value.replaceAll(',', '');
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
});
amountsController.clear(); // تفريغ الحقل خارج setState
},
),
const SizedBox(height: 24),
// Action Buttons
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
OutlinedButton(
onPressed: () => Navigator.pop(context),
style: OutlinedButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.onSurface,
side: BorderSide(
color: Theme.of(context).colorScheme.outline.withOpacity(0.4),
),
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'تخطي',
style: TextStyle(
fontFamily: tajawalFont,
fontSize: 15,
),
),
),
const SizedBox(width: 12),
ElevatedButton(
onPressed: () async {
if (_savedAmounts.isEmpty) {
_showSnackBar('الرجاء إدخال مبلغ واحد على الأقل');
return;
}
await _saveSavedAmounts();
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'حفظ',
style: TextStyle(
fontFamily: tajawalFont,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
],
),
],
),
),
),
);
},
);
},
);
Show full message · 275 lines Assistant2025-05-22 08:01 UTC Copy response
يمكنك تعديل جزء إضافة المبلغ بحيث يتم تفريغ الحقل بعد إضافة المبلغ مباشرة، وذلك باستخدام setState مع تفريغ الحقل، أو تفريغ الحقل خارج setState مع تحديث الواجهة بشكل صحيح.
في الكود الذي أرفقته، أنت تفريغ الحقل (amountsController.clear()) بعد الـ setState، وهذا صحيح، لكن يمكنك تحسين السلوك عند إضافة المبلغ كالتالي:
التعديل المقترح:
قم بوضع تفريغ الحقل amountsController.clear() داخل الـ setState لكي يتم تحديث الشاشة (وليس خارجها)، وذلك هكذا:
dart Copy code
onPressed: () {
final raw = amountsController.text.replaceAll(',', '');
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
amountsController.clear(); // هنا ضمن setState
});
},
ونفس الشيء في onSubmitted:
dart Copy code
onSubmitted: (value) {
final raw = value.replaceAll(',', '');
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
amountsController.clear(); // هنا ضمن setState
});
},
ملاحظات إضافية:
من الأفضل دومًا تحديث الحالة أي setState عندما يتغير المحتوى الذي يؤثر على الـ UI، مثل تغيير نص الـ TextField.
تجد في الكود أنك تستخدم WidgetsBinding.instance.addPostFrameCallback لتحديث قيمة amountsController.text بناءً على _savedAmounts. تأكد أن هذا لا يتسبب بتضارب مع التحديثات المتكررة.
إذا تحتاج مثال كامل للجزء المعدل فقط أو توضيحات إضافية لا تتردد بالسؤال.
اعطيني الكود الكامل بعد التعديل لاقوم باستخدامة مباشرة
Assistant2025-05-22 08:01 UTC Copy response
بالطبع، إليك الكود كاملًا بعد التعديل حيث تم وضع amountsController.clear() داخل دالة setState في الـ onPressed وأيضًا في الـ onSubmitted لضمان تفريغ الحقل فور إضافة المبلغ:
Show full message · 288 lines لماذا يختفي ثم يظهر اريد حل لهذة المشكلة كما اريد ان يكون هناك خلفية رمادية باهتة حقل ادخل المبالغ او اسلوب افضل
Assistant2025-05-22 08:04 UTC Copy response
لفهم سؤالك التفصيلي:
لماذا "يختفي ثم يظهر" عند تفريغ حقل الإدخال (TextField) بعد إضافة مبلغ؟
كيف تجعل خلفية حقل الإدخال رمادية باهتة أو تحسن الشكل بأسلوب أفضل؟
1. سبب اختفاء ثم ظهور حقل الإدخال (Flickering)
عادةً يحدث هذا السلوك لأن ضبط قيمة amountsController.text أو تفريغها يحدث بطريقة تؤدي إلى إعادة بناء (rebuild) متكررة ومتداخلة أو بسبب تحديث الـ TextEditingController داخل setState بشكل غير مثالي، أو بسبب استخدام WidgetsBinding.instance.addPostFrameCallback الموجود في كودك والذي قد يؤثر على القيمة في أوقات غير متوقعه.
بعض الخطوات والتعديلات لحل المشكلة:
عدم تحديث amountsController.text إلا عند الضرورة : لا تكتب إلى amountsController.text أثناء إعادة البناء إن لم يكن ضرورياً. قم بفحص القيمة الحالية قبل تعيينها.
تأكّد أن وظيفة addPostFrameCallback لا تسبب تحديث غير متوقع أو تعيد تعيين النص حتى بدون حاجة.
اقتراح تعديل من أجل تجنب الوميض:
في كودك:
dart Copy code
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_savedAmounts.isNotEmpty && amountsController.text.isEmpty) {
amountsController.text = _formatWithThousandsSeparator(_savedAmounts.first);
}
});
هذه الوظيفة ستُعيد تعيين النص في كل إعادة بناء طالما كان الحقل فارغًا، وهذا قد يسبب وميض.
يمكنك استبدالها بشيء مثل:
dart Copy code
if (_savedAmounts.isNotEmpty && amountsController.text.isEmpty) {
// عيّن النص فقط إذا ليس نفسه النص الحالي
final formatted = _formatWithThousandsSeparator(_savedAmounts.first);
if (amountsController.text != formatted) {
amountsController.text = formatted;
}
}
وأيضاً يفضل نقل هذا المنطق من داخل الـ builder إلى مكان يتم فيه استدعاء الديالوج، أو قبله مباشرةً لتجنب إعادة التعيين الدائم.
2. تحسين خلفية حقل الإدخال (Container محيط أو color داخل InputDecoration)
في كودك:
اعطيني الكود الكامل بعد التعديل لاقوم باستخدامة مباشرة
Assistant2025-05-22 08:04 UTC Copy response
بالطبع! فيما يلي الكود الكامل بعد التعديلات المطلوبة:
إزالة استخدام WidgetsBinding.instance.addPostFrameCallback من داخل الـ StatefulBuilder لمنع وميض الحقل.
تعيين قيمة amountsController.text لمرة واحدة قبل فتح الـ dialog (يمكنك تعديل مكان هذا حسب حاجتك).
خلفية حقل الإدخال (TextField) أصبحت لون رمادي باهت Colors.grey.withOpacity(0.15).
تفريغ الحقل داخل setState بعد إضافة المبلغ لتحديث واجهة المستخدم بسلاسة.
الكود:
Show full message · 300 lines اجعل هذا التصميم كا السابق
await showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text(
'إدارة المحفظة الرقيمة',
style: TextStyle(fontFamily: tajawalFont),
textAlign: TextAlign.center,
),
content: StatefulBuilder(
builder: (context, setDialogState) {
return SizedBox(
width: double.maxFinite,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (_savedAmounts.isEmpty)
Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Text(
'لا توجد مبالغ محفوظة حالياً',
style: Theme.of(
context,
).textTheme.bodyMedium?.copyWith(
fontFamily: tajawalFont,
color:
Theme.of(context).colorScheme.onSurfaceVariant,
),
),
),
if (_savedAmounts.isNotEmpty)
Container(
constraints: BoxConstraints(maxHeight: 150),
child: SingleChildScrollView(
child: Wrap(
spacing: 8,
runSpacing: 6,
children:
_savedAmounts
.map(
(amt) => Tooltip(
message: 'حذف هذا المبلغ',
child: Chip(
label: Text(
_formatWithThousandsSeparator(amt),
style: const TextStyle(
fontFamily: tajawalFont,
fontWeight: FontWeight.w600,
),
),
backgroundColor:
Theme.of(
context,
).colorScheme.primaryContainer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
20,
),
),
onDeleted: () {
setDialogState(() {
_savedAmounts.remove(amt);
});
},
deleteIconColor:
Theme.of(
context,
).colorScheme.error,
),
),
)
.toList(),
),
),
),
const Divider(height: 25, thickness: 1),
TextField(
controller: amountsController,
keyboardType: TextInputType.number,
inputFormatters: [ThousandsSeparatorInputFormatter()],
decoration: InputDecoration(
labelText: 'إضافة مبلغ جديد',
suffixIcon: IconButton(
icon: const Icon(Icons.add_circle_rounded),
tooltip: 'إضافة المبلغ',
onPressed:
isValidInput(amountsController.text)
? () => addAmount(
amountsController.text,
setDialogState,
)
: null,
),
),
onChanged: (value) {
setDialogState(() {}); // لتحديث زر الإضافة
},
onSubmitted: (value) {
addAmount(value, setDialogState);
},
),
],
),
);
},
),
actionsAlignment: MainAxisAlignment.spaceBetween,
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text(
'إغلاق',
style: TextStyle(fontFamily: tajawalFont),
),
),
FilledButton.tonal(
onPressed: () async {
await _saveSavedAmounts();
Navigator.pop(context);
_showSnackBar('تم حفظ المبالغ بنجاح');
},
child: const Text(
'حفظ',
style: TextStyle(fontFamily: tajawalFont),
),
),
],
);
},
);
Show full message · 131 lines Assistant2025-05-22 08:12 UTC Copy response
بالتأكيد، سأقوم بتعديل تصميم الـ AlertDialog الذي أرفقته ليُشابه التصميم السابق الذي يحتوي على:
عنوان بالمنتصف
قائمة المبالغ المحفوظة مع إمكانية حذفها (باستخدام Chips)
حقل إدخال مع خلفية رمادية باهتة وحقل إدخال به زر إضافة
أزرار حفظ وإغلاق في الأسفل مع توزيع مناسب
كما سأدرج وظيفة إضافة المبلغ مع التحقق من صحة المبلغ وإفراغ الحقل بعد الإضافة.
الكود كامل بعد التعديل والتنسيق:
Show full message · 222 lines لماذا لم تجعلة مثل السابق تماماً من حيث التصميم وايقونة الملف وباقي الاشياء
Assistant2025-05-22 08:14 UTC Copy response
فهمت قصدك، تريد الـ AlertDialog بالضبط مثل تصميم الـ Dialog السابق مع:
شكل الـ dialog بزاوية دائرية كبيرة (مثل RoundedRectangleBorder مع نصف قطر 24)
ترويسة تحتوي على أيقونة المحفظة + العنوان مع التنسيق نفسه
قائمة المبالغ المحفوظة بشكل قائمة مع خيارات حذف كما في السابق (وليس Chip)
حقل الإدخال مع خلفية رمادية باهتة ونفس تصميم زر الإضافة
أزرار الحفظ والإغلاق بنفس التصميم والموقع
إليك الكود المعدل ليطابق التوقعات تمامًا بناء على الكود الأول الذي أرفقته لكن ضمن AlertDialog مع StatefulBuilder للتحكم في الحالة وكذلك شكل أقرب قدر الإمكان للتصميم السابق:
Show full message · 291 lines ظهرت مشكلة تدخل الازرار الخاطة بالحفظ وتخطي مع الحقل وظهر bottom overloaded by pixel
Assistant2025-05-22 08:17 UTC Copy response
المشكلة التي تواجهها ناتجة عادة من:
ارتفاع المحتوى في AlertDialog أكثر من المساحة المتاحة على الشاشة.
عدم وجود لفّ (scrolling) مناسب في المحتوى، خاصّة حين ظهور لوحة المفاتيح.
تداخل أزرار العمليات (الحفظ و التخطي) مع الحقل النصّي.
لحل المشكلة وتفادي الخطأ "Bottom overflowed by pixels" وجعل التصميم مريحًا ومستجيبًا حتى مع ظهور لوحة المفاتيح:
الحل هو:
لف محتوى الديالوج (بما فيه قائمة المبالغ والحقل) داخل Flexible أو Expanded أو لفّه بـ SingleChildScrollView مع تحديد ارتفاع مناسب.
وضع أزرار الـ actions خارج الـ SingleChildScrollView (كما هو في AlertDialog).
استخدام MediaQuery لتجنب تداخل لوحة المفاتيح.
ربما وضع الـ content داخل ConstrainedBox مع maxHeight.
تعديل على كودك الحالي ليكون أكثر مرونة:
Show full message · 312 lines الان اختفت النافذة بالكامل
Assistant2025-05-22 08:21 UTC Copy response
اختفاء النافذة بالكامل عادةً يحصل بسبب:
استخدام Expanded أو Flexible داخل Column في مكان لا يسمح له بأخذ مساحة (خصوصًا داخل AlertDialog حيث content لا يملك مساحة محددة أو قابل للتوسيع)
أو مشكلة في قيود الحجم (BoxConstraints) التي تجعل الـ widget تختفي (مثل تعارض ConstrainedBox مع محتوى غير قابل للتمدد)
كيفية إصلاح المشكلة:
في AlertDialog عند استخدام content:
لا يجب وضع Expanded مباشرة داخل Column في content لأنه يحتاج إلى والد له حجم محدود (مثل SizedBox أو Flexible ضمن Flex أعلى) .
استبدل الـ Expanded بـ إما Flexible أو لف المحتوى كله في SingleChildScrollView وتحديد ارتفاع ثابت مناسب عبر SizedBox أو ConstrainedBox.
تعديل سريع على الكود:
بدلاً من:
dart Copy code
return ConstrainedBox(
constraints: BoxConstraints(
maxHeight: maxHeight,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
...
),
),
),
],
),
);
يجب استبداله بـ:
Show full message · 458 lines Copy first response
Not yet included in a published release.
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_savedAmounts.isNotEmpty && amountsController.text.isEmpty) {
amountsController.text = _formatWithThousandsSeparator(_savedAmounts.first);
}
});
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
elevation: 8,
insetPadding: const EdgeInsets.all(20),
child: SingleChildScrollView(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 20),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: BorderRadius.circular(24),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header
Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(
Icons.monetization_on_rounded,
size: 28,
color: Theme.of(context).colorScheme.primary,
),
),
const SizedBox(width: 12),
Text(
'المحفظة الرقمية',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurface,
),
),
],
),
const SizedBox(height: 24),
// Saved Amounts List
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.1),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Theme.of(context).colorScheme.outline.withOpacity(0.1),
),
),
child: _savedAmounts.isEmpty
? Column(
children: [
Icon(
Icons.wallet_rounded,
size: 40,
color: Theme.of(context).colorScheme.primary.withOpacity(0.5),
),
const SizedBox(height: 12),
Text(
'أضف المبالغ التي تريد استخدامها بشكل متكرر',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontSize: 14,
),
textAlign: TextAlign.center,
),
],
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'اختر من المبالغ المحفوظة:',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 12),
SizedBox(
height: 120,
child: ListView.builder(
itemCount: _savedAmounts.length,
itemBuilder: (context, index) {
final amount = _savedAmounts[index];
return ListTile(
contentPadding: EdgeInsets.zero,
leading: Radio<int>(
value: amount,
groupValue: _savedAmounts.first,
onChanged: (value) {
setState(() {
amountsController.text = _formatWithThousandsSeparator(value!);
});
},
),
title: Text(
_formatWithThousandsSeparator(amount),
style: TextStyle(
fontFamily: tajawalFont,
fontWeight: FontWeight.w600,
),
),
trailing: IconButton(
icon: Icon(
Icons.delete_outline,
color: Theme.of(context).colorScheme.error,
),
onPressed: () {
setState(() {
_savedAmounts.remove(amount);
if (_savedAmounts.isNotEmpty) {
amountsController.text =
_formatWithThousandsSeparator(_savedAmounts.first);
} else {
amountsController.clear();
}
});
},
),
);
},
),
),
],
),
),
const SizedBox(height: 20),
// Amount Input Field
TextField(
controller: amountsController,
keyboardType: TextInputType.number,
inputFormatters: [ThousandsSeparatorInputFormatter()],
decoration: InputDecoration(
labelText: 'أو أدخل مبلغًا جديدًا',
labelStyle: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
suffixIcon: IconButton(
icon: Icon(
Icons.add_circle_rounded,
color: Theme.of(context).colorScheme.primary,
size: 28,
),
onPressed: () {
final raw = amountsController.text.replaceAll(',', '');
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
amountsController.clear(); // تفريغ الحقل داخل setState
});
},
),
filled: true,
fillColor: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.1),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: BorderSide.none,
),
),
onSubmitted: (value) {
final raw = value.replaceAll(',', '');
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
amountsController.clear(); // تفريغ الحقل داخل setState
});
},
),
const SizedBox(height: 24),
// Action Buttons
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
OutlinedButton(
onPressed: () => Navigator.pop(context),
style: OutlinedButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.onSurface,
side: BorderSide(
color: Theme.of(context).colorScheme.outline.withOpacity(0.4),
),
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'تخطي',
style: TextStyle(
fontFamily: tajawalFont,
fontSize: 15,
),
),
),
const SizedBox(width: 12),
ElevatedButton(
onPressed: () async {
if (_savedAmounts.isEmpty) {
_showSnackBar('الرجاء إدخال مبلغ واحد على الأقل');
return;
}
await _saveSavedAmounts();
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'حفظ',
style: TextStyle(
fontFamily: tajawalFont,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
],
),
],
),
),
),
);
},
);
},
);
ما تم تغييره فقط:
نقل استدعاء amountsController.clear() داخل دالة setState في مكاني الإضافة عبر زر الأيقونة (onPressed) و عبر الـ onSubmitted أيضاً.
بهذه الطريقة عند الضغط على أيقونة الإضافة أو عند الإرسال من لوحة المفاتيح يتم تحديث الواجهة وتفريغ الحقل مباشرة بما يضمن ظهور النص الجديد فقط، ويصبح الحقل فارغًا لتدخل مبلغ جديد.
إذا احتجت أي تعديل إضافي أو لديك استفسار آخر فأنا جاهز للمساعدة.
decoration: InputDecoration(
//...
filled: true,
fillColor: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.1),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: BorderSide.none,
),
),
هذا أسلوب جيد، لكنه قد يظهر ضعيفًا جدًا أو مختلفًا حسب الثيم.
اقتراح تحسين الخلفية لتكون رمادية باهتة بشكل واضح: يمكنك ضبط fillColor إلى لون رمادي فاتح أكثر ثباتاً مثل:
dart Copy code
fillColor: Colors.grey.withOpacity(0.15),
أو تستخدم لون ثابت من الثيم لو لم تكن تريد الاتكال على surfaceVariant فقط.
مثال كامل على تعديل الجزء الخاص بـ TextField مع نص محفوظ وعدم وميض: dart Copy code
// في مكان الـ StatefulBuilder داخل builder:
// لا تستخدم addPostFrameCallback داخل builder، قم بهذا التحقق مرة واحدة عند فتح الديالوج فقط
// مثلاً قبل استدعاء showDialog في الكود الرئيسي:
// if (_savedAmounts.isNotEmpty && amountsController.text.isEmpty) {
// amountsController.text = _formatWithThousandsSeparator(_savedAmounts.first);
// }
// أما داخل builder فلا تعيد تعيين النص، فقط استخدم القيم كما هي
// وفي TextField:
TextField(
controller: amountsController,
keyboardType: TextInputType.number,
inputFormatters: [ThousandsSeparatorInputFormatter()],
decoration: InputDecoration(
labelText: 'أو أدخل مبلغًا جديدًا',
labelStyle: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
suffixIcon: IconButton(
icon: Icon(
Icons.add_circle_rounded,
color: Theme.of(context).colorScheme.primary,
size: 28,
),
onPressed: () {
final raw = amountsController.text.replaceAll(',', '');
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
amountsController.clear();
});
},
),
filled: true,
fillColor: Colors.grey.withOpacity(0.15), // لون رمادي باهت واضح
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: BorderSide.none,
),
),
onSubmitted: (value) {
final raw = value.replaceAll(',', '');
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
amountsController.clear();
});
},
),
ملخص الحلول:
أزل أو نقل تعيين amountsController.text من داخل addPostFrameCallback أو ضع شرط صارم للتعيين فقط إذا مختلف عن الحالي .
استخدم لون خلفية ثابت ومناسب في fillColor لجعل الحقل ذو خلفية رمادية باهتة واضحة.
اجعل التفريغ داخل setState بعد الإضافة لضمان تحديث الواجهة بدون تداخل غير مرغوب.
إذا ترغب يمكنني مساعدتك بإعادة كتابة الكود مع هذه التعديلات جاهزة للنسخ. هل تريد ذلك؟
// قبل استخدام showDialog مباشرة، عيّن النص إذا أردت مثلاً:
if (_savedAmounts.isNotEmpty && amountsController.text.isEmpty) {
amountsController.text = _formatWithThousandsSeparator(_savedAmounts.first);
}
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
elevation: 8,
insetPadding: const EdgeInsets.all(20),
child: SingleChildScrollView(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 20),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: BorderRadius.circular(24),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header
Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(
Icons.monetization_on_rounded,
size: 28,
color: Theme.of(context).colorScheme.primary,
),
),
const SizedBox(width: 12),
Text(
'المحفظة الرقمية',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurface,
),
),
],
),
const SizedBox(height: 24),
// Saved Amounts List
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.1),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Theme.of(context).colorScheme.outline.withOpacity(0.1),
),
),
child: _savedAmounts.isEmpty
? Column(
children: [
Icon(
Icons.wallet_rounded,
size: 40,
color: Theme.of(context).colorScheme.primary.withOpacity(0.5),
),
const SizedBox(height: 12),
Text(
'أضف المبالغ التي تريد استخدامها بشكل متكرر',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontSize: 14,
),
textAlign: TextAlign.center,
),
],
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'اختر من المبالغ المحفوظة:',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 12),
SizedBox(
height: 120,
child: ListView.builder(
itemCount: _savedAmounts.length,
itemBuilder: (context, index) {
final amount = _savedAmounts[index];
return ListTile(
contentPadding: EdgeInsets.zero,
leading: Radio<int>(
value: amount,
groupValue: _savedAmounts.first,
onChanged: (value) {
setState(() {
amountsController.text = _formatWithThousandsSeparator(value!);
});
},
),
title: Text(
_formatWithThousandsSeparator(amount),
style: TextStyle(
fontFamily: tajawalFont,
fontWeight: FontWeight.w600,
),
),
trailing: IconButton(
icon: Icon(
Icons.delete_outline,
color: Theme.of(context).colorScheme.error,
),
onPressed: () {
setState(() {
_savedAmounts.remove(amount);
if (_savedAmounts.isNotEmpty) {
amountsController.text =
_formatWithThousandsSeparator(_savedAmounts.first);
} else {
amountsController.clear();
}
});
},
),
);
},
),
),
],
),
),
const SizedBox(height: 20),
// Amount Input Field
TextField(
controller: amountsController,
keyboardType: TextInputType.number,
inputFormatters: [ThousandsSeparatorInputFormatter()],
decoration: InputDecoration(
labelText: 'أو أدخل مبلغًا جديدًا',
labelStyle: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
suffixIcon: IconButton(
icon: Icon(
Icons.add_circle_rounded,
color: Theme.of(context).colorScheme.primary,
size: 28,
),
onPressed: () {
final raw = amountsController.text.replaceAll(',', '');
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
amountsController.clear(); // التفريغ داخل setState
});
},
),
filled: true,
fillColor: Colors.grey.withOpacity(0.15), // خلفية رمادية باهتة
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: BorderSide.none,
),
),
onSubmitted: (value) {
final raw = value.replaceAll(',', '');
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
amountsController.clear(); // التفريغ داخل setState
});
},
),
const SizedBox(height: 24),
// Action Buttons
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
OutlinedButton(
onPressed: () => Navigator.pop(context),
style: OutlinedButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.onSurface,
side: BorderSide(
color: Theme.of(context).colorScheme.outline.withOpacity(0.4),
),
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'تخطي',
style: TextStyle(
fontFamily: tajawalFont,
fontSize: 15,
),
),
),
const SizedBox(width: 12),
ElevatedButton(
onPressed: () async {
if (_savedAmounts.isEmpty) {
_showSnackBar('الرجاء إدخال مبلغ واحد على الأقل');
return;
}
await _saveSavedAmounts();
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'حفظ',
style: TextStyle(
fontFamily: tajawalFont,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
],
),
],
),
),
),
);
},
);
},
);
نقاط مهمة:
إذا كنت تستخدم amountsController.text في أكثر من مكان وتحتاج إعادة تعيينه في الديالوج، فقم بتعيينه مرة واحدة قبل استدعاء showDialog وليس في الـ builder لتفادي الوميض.
الخلفية الرمادية باهتة تم تعيينها عبر fillColor: Colors.grey.withOpacity(0.15) وهذا يعطي مظهر واضح وناعم.
تفريغ الحقل عبر amountsController.clear() داخل setState يضمن تحديث واجهة المستخدم بسلاسة.
إذا تحتاج أي تعديل إضافي أو دمج مع كود كامل أوشرح كيف تحدد النص المبدئي قبل فتح الديالوج فأخبرني بذلك!
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
title: Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(
Icons.monetization_on_rounded,
size: 28,
color: Theme.of(context).colorScheme.primary,
),
),
const SizedBox(width: 12),
Text(
'المحفظة الرقمية',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurface,
),
),
],
),
),
content: StatefulBuilder(
builder: (context, setDialogState) {
// دالة مساعدة لإضافة مبلغ مع تحديث الحالة
void addAmount(String value, void Function(void Function()) setState) {
final raw = value.replaceAll(',', '').trim();
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
amountsController.clear();
});
}
// دالة تحقق من صلاحية الإدخال ليتم تمكين زر الإضافة
bool isValidInput(String text) {
final raw = text.replaceAll(',', '').trim();
final numAmount = int.tryParse(raw);
return numAmount != null && numAmount > 0 && !_savedAmounts.contains(numAmount);
}
return SizedBox(
width: double.maxFinite,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (_savedAmounts.isEmpty)
Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: Text(
'لا توجد مبالغ محفوظة حالياً',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
),
),
if (_savedAmounts.isNotEmpty)
Container(
constraints: const BoxConstraints(maxHeight: 140),
padding: const EdgeInsets.symmetric(vertical: 8),
child: SingleChildScrollView(
child: Wrap(
spacing: 8,
runSpacing: 6,
children: _savedAmounts
.map(
(amt) => Tooltip(
message: 'حذف هذا المبلغ',
child: Chip(
label: Text(
_formatWithThousandsSeparator(amt),
style: const TextStyle(
fontFamily: tajawalFont,
fontWeight: FontWeight.w600,
),
),
backgroundColor: Theme.of(context)
.colorScheme
.primaryContainer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
onDeleted: () {
setDialogState(() {
_savedAmounts.remove(amt);
});
},
deleteIconColor:
Theme.of(context).colorScheme.error,
),
),
)
.toList(),
),
),
),
const Divider(height: 32, thickness: 1),
TextField(
controller: amountsController,
keyboardType: TextInputType.number,
inputFormatters: [ThousandsSeparatorInputFormatter()],
decoration: InputDecoration(
labelText: 'أدخل مبلغًا جديدًا',
filled: true,
fillColor: Colors.grey.withOpacity(0.15),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: BorderSide.none,
),
suffixIcon: IconButton(
icon: Icon(
Icons.add_circle_rounded,
color: isValidInput(amountsController.text)
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurface.withOpacity(0.3),
size: 28,
),
tooltip: 'إضافة المبلغ',
onPressed: isValidInput(amountsController.text)
? () {
addAmount(amountsController.text, setDialogState);
}
: null,
),
),
onChanged: (value) {
setDialogState(() {});
},
onSubmitted: (value) {
addAmount(value, setDialogState);
},
),
],
),
);
},
),
actionsAlignment: MainAxisAlignment.spaceBetween,
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(
'إغلاق',
style: TextStyle(fontFamily: tajawalFont),
),
),
FilledButton.tonal(
onPressed: () async {
if (_savedAmounts.isEmpty) {
_showSnackBar('الرجاء إدخال مبلغ واحد على الأقل');
return;
}
await _saveSavedAmounts();
Navigator.pop(context);
_showSnackBar('تم حفظ المبالغ بنجاح');
},
child: Text(
'حفظ',
style: TextStyle(fontFamily: tajawalFont),
),
),
],
);
},
);
ملاحظات:
addAmount وisValidInput مرفقتان داخل الـ StatefulBuilder لتسهيل التحكم في الحالة.
حقل الإدخال يحتوي على خلفية رمادية باهتة و suffixIcon يظهر ملونًا فقط عند وجود إدخال صالح.
زر الحذف في الـ Chip يظهر أيقونة الحذف باللون الأحمر.
العنوان يحتوي على أيقونة وتنسيق يشبه التصميم السابق.
زر الحفظ يمنع الحفظ إذا لم توجد مبالغ، ويعطي رسالة توضيحية.
استخدمت FilledButton.tonal وفقًا لتصميمك السابق (تأكد أن FilledButton متوافقة مع الإصدار الذي تستخدمه من فلتر).
إذا تريد أساعدك في دمج amountsController أو _savedAmounts أو وظائف _showSnackBar و _saveSavedAmounts فقط أخبرني!
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
elevation: 8,
insetPadding: const EdgeInsets.all(20),
titlePadding: EdgeInsets.zero,
contentPadding: const EdgeInsets.fromLTRB(24, 20, 24, 24),
title: Padding(
padding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(
Icons.monetization_on_rounded,
size: 28,
color: Theme.of(context).colorScheme.primary,
),
),
const SizedBox(width: 12),
Text(
'المحفظة الرقمية',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurface,
),
),
],
),
),
content: StatefulBuilder(
builder: (context, setDialogState) {
void addAmount(String value, void Function(void Function()) setState) {
final raw = value.replaceAll(',', '').trim();
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
amountsController.clear();
});
}
bool isValidInput(String text) {
final raw = text.replaceAll(',', '').trim();
final numAmount = int.tryParse(raw);
return numAmount != null && numAmount > 0 && !_savedAmounts.contains(numAmount);
}
return SizedBox(
width: double.maxFinite,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.1),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Theme.of(context).colorScheme.outline.withOpacity(0.1),
),
),
child: _savedAmounts.isEmpty
? Column(
children: [
Icon(
Icons.wallet_rounded,
size: 40,
color: Theme.of(context).colorScheme.primary.withOpacity(0.5),
),
const SizedBox(height: 12),
Text(
'أضف المبالغ التي تريد استخدامها بشكل متكرر',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontSize: 14,
),
textAlign: TextAlign.center,
),
],
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'اختر من المبالغ المحفوظة:',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 12),
SizedBox(
height: 120,
child: ListView.builder(
itemCount: _savedAmounts.length,
itemBuilder: (context, index) {
final amount = _savedAmounts[index];
return ListTile(
contentPadding: EdgeInsets.zero,
leading: Radio<int>(
value: amount,
groupValue: _savedAmounts.first,
onChanged: (value) {
setDialogState(() {
amountsController.text = _formatWithThousandsSeparator(value!);
});
},
),
title: Text(
_formatWithThousandsSeparator(amount),
style: TextStyle(
fontFamily: tajawalFont,
fontWeight: FontWeight.w600,
),
),
trailing: IconButton(
icon: Icon(
Icons.delete_outline,
color: Theme.of(context).colorScheme.error,
),
onPressed: () {
setDialogState(() {
_savedAmounts.remove(amount);
if (_savedAmounts.isNotEmpty) {
amountsController.text =
_formatWithThousandsSeparator(_savedAmounts.first);
} else {
amountsController.clear();
}
});
},
),
);
},
),
),
],
),
),
const SizedBox(height: 20),
TextField(
controller: amountsController,
keyboardType: TextInputType.number,
inputFormatters: [ThousandsSeparatorInputFormatter()],
decoration: InputDecoration(
labelText: 'أو أدخل مبلغًا جديدًا',
filled: true,
fillColor: Colors.grey.withOpacity(0.15),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: BorderSide.none,
),
suffixIcon: IconButton(
icon: Icon(
Icons.add_circle_rounded,
color: isValidInput(amountsController.text)
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurface.withOpacity(0.3),
size: 28,
),
onPressed: isValidInput(amountsController.text)
? () {
addAmount(amountsController.text, setDialogState);
}
: null,
),
),
onChanged: (value) {
setDialogState(() {});
},
onSubmitted: (value) {
addAmount(value, setDialogState);
},
),
],
),
);
},
),
actionsPadding: const EdgeInsets.fromLTRB(24, 0, 24, 24),
actionsAlignment: MainAxisAlignment.end,
actions: [
OutlinedButton(
onPressed: () => Navigator.pop(context),
style: OutlinedButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.onSurface,
side: BorderSide(
color: Theme.of(context).colorScheme.outline.withOpacity(0.4),
),
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'تخطي',
style: TextStyle(
fontFamily: tajawalFont,
fontSize: 15,
),
),
),
const SizedBox(width: 12),
ElevatedButton(
onPressed: () async {
if (_savedAmounts.isEmpty) {
_showSnackBar('الرجاء إدخال مبلغ واحد على الأقل');
return;
}
await _saveSavedAmounts();
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'حفظ',
style: TextStyle(
fontFamily: tajawalFont,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
],
);
},
);
شرح التعديلات:
استخدمت AlertDialog مع تغيير شكل الـ dialog إلى الشكل الدائري الكبير (مثل السابق) عبر shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)).
أضفت العنوان بخط واضح مع أيقونة المحفظة بالتصميم والتلوين السابق.
كتلة عرض المبالغ المحفوظة نفسها حفظتها كما كانت ولكن داخل Container مع خلفية باهتة وحدود شفافة.
قائمة المبالغ محفوظة على شكل ListView مع Radio وتستطيع حذف أي عنصر بزر الحذف (أيكون Icons.delete_outline).
حقل النص يحتوي على تعبئة filled: true مع خلفية رمادية باهتة (opacity 0.15) وزر إضافة متفاعل مع حالة صحة الإدخال (onPressed يتغير حسب حالة الإدخال).
الأزرار في الأسفل منسقة وذات نفس الألوان والحواف والPadding كما في التصميم السابق.
أزرار: "تخطي" (OutlinedButton) و "حفظ" (ElevatedButton) بنفس التنسيق.
StatefulBuilder للحفاظ على state داخلي في المحتوى.
إذا تريد أرسل لك نسخة مع دمج كامل لكل التعريفات المتغيرة (_savedAmounts, amountsController,... يمكنك طلب ذلك) أو شرح وظيفة _showSnackBar و _saveSavedAmounts وأين تحققهما.
هل هذا التصميم يطابق المطلوب؟ أم تريد تعديل شيء آخر؟
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
elevation: 8,
insetPadding: const EdgeInsets.all(20),
titlePadding: EdgeInsets.zero,
contentPadding: const EdgeInsets.fromLTRB(24, 20, 24, 24),
title: Padding(
padding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(
Icons.monetization_on_rounded,
size: 28,
color: Theme.of(context).colorScheme.primary,
),
),
const SizedBox(width: 12),
Text(
'المحفظة الرقمية',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurface,
),
),
],
),
),
content: StatefulBuilder(
builder: (context, setDialogState) {
void addAmount(String value, void Function(void Function()) setState) {
final raw = value.replaceAll(',', '').trim();
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
amountsController.clear();
});
}
bool isValidInput(String text) {
final raw = text.replaceAll(',', '').trim();
final numAmount = int.tryParse(raw);
return numAmount != null && numAmount > 0 && !_savedAmounts.contains(numAmount);
}
final maxHeight = MediaQuery.of(context).size.height * 0.5; // حدد ارتفاع معقول
return ConstrainedBox(
constraints: BoxConstraints(
maxHeight: maxHeight,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.1),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Theme.of(context).colorScheme.outline.withOpacity(0.1),
),
),
child: _savedAmounts.isEmpty
? Column(
children: [
Icon(
Icons.wallet_rounded,
size: 40,
color: Theme.of(context).colorScheme.primary.withOpacity(0.5),
),
const SizedBox(height: 12),
Text(
'أضف المبالغ التي تريد استخدامها بشكل متكرر',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontSize: 14,
),
textAlign: TextAlign.center,
),
],
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'اختر من المبالغ المحفوظة:',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 12),
SizedBox(
height: 120,
child: ListView.builder(
itemCount: _savedAmounts.length,
itemBuilder: (context, index) {
final amount = _savedAmounts[index];
return ListTile(
contentPadding: EdgeInsets.zero,
leading: Radio<int>(
value: amount,
groupValue: _savedAmounts.first,
onChanged: (value) {
setDialogState(() {
amountsController.text = _formatWithThousandsSeparator(value!);
});
},
),
title: Text(
_formatWithThousandsSeparator(amount),
style: TextStyle(
fontFamily: tajawalFont,
fontWeight: FontWeight.w600,
),
),
trailing: IconButton(
icon: Icon(
Icons.delete_outline,
color: Theme.of(context).colorScheme.error,
),
onPressed: () {
setDialogState(() {
_savedAmounts.remove(amount);
if (_savedAmounts.isNotEmpty) {
amountsController.text =
_formatWithThousandsSeparator(_savedAmounts.first);
} else {
amountsController.clear();
}
});
},
),
);
},
),
),
],
),
),
const SizedBox(height: 20),
TextField(
controller: amountsController,
keyboardType: TextInputType.number,
inputFormatters: [ThousandsSeparatorInputFormatter()],
decoration: InputDecoration(
labelText: 'أو أدخل مبلغًا جديدًا',
filled: true,
fillColor: Colors.grey.withOpacity(0.15),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: BorderSide.none,
),
suffixIcon: IconButton(
icon: Icon(
Icons.add_circle_rounded,
color: isValidInput(amountsController.text)
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurface.withOpacity(0.3),
size: 28,
),
onPressed: isValidInput(amountsController.text)
? () {
addAmount(amountsController.text, setDialogState);
}
: null,
),
),
onChanged: (value) {
setDialogState(() {});
},
onSubmitted: (value) {
addAmount(value, setDialogState);
},
),
],
),
),
),
],
),
);
},
),
actionsPadding: const EdgeInsets.fromLTRB(24, 0, 24, 24),
actionsAlignment: MainAxisAlignment.end,
actions: [
OutlinedButton(
onPressed: () => Navigator.pop(context),
style: OutlinedButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.onSurface,
side: BorderSide(
color: Theme.of(context).colorScheme.outline.withOpacity(0.4),
),
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'تخطي',
style: TextStyle(
fontFamily: tajawalFont,
fontSize: 15,
),
),
),
const SizedBox(width: 12),
ElevatedButton(
onPressed: () async {
if (_savedAmounts.isEmpty) {
_showSnackBar('الرجاء إدخال مبلغ واحد على الأقل');
return;
}
await _saveSavedAmounts();
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'حفظ',
style: TextStyle(
fontFamily: tajawalFont,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
],
);
},
);
ملخص التحسينات:
لفّت المحتوى داخل ConstrainedBox للحفاظ على أقصى ارتفاع نسبي من الشاشة (50% هنا).
استخدمت SingleChildScrollView مع Expanded داخل الـ column لتجنب مشاكل تجاوز ارتفاع المحتوى.
بقاء أزرار actions ثابتة في أسفل الـ dialog ولا تتداخل مع باقي المحتوى.
التصميم مطابق للنسخة السابقة مع الحفاظ على تحسين تجربة الاستخدام عند ظهور لوحة المفاتيح.
من أن تستخدم amountsController و setDialogState بشكل صحيح.
عدم وجود استدعاءات تعيد بناء غير ضرورية تضيف للمشكلة.
عند اختبار على أجهزة بأحجام شاشة صغيرة خصوصًا مع لوحة المفاتيح.
هل تريد نسخة كاملة مع المزيد من الفحص لجعلها تشتغل بسلاسة ومتوافقة مع جميع الشاشات؟
return ConstrainedBox(
constraints: BoxConstraints(
maxHeight: maxHeight,
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.1),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Theme.of(context).colorScheme.outline.withOpacity(0.1),
),
),
child: _savedAmounts.isEmpty
? Column(
children: [
Icon(
Icons.wallet_rounded,
size: 40,
color: Theme.of(context).colorScheme.primary.withOpacity(0.5),
),
const SizedBox(height: 12),
Text(
'أضف المبالغ التي تريد استخدامها بشكل متكرر',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontSize: 14,
),
textAlign: TextAlign.center,
),
],
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'اختر من المبالغ المحفوظة:',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 12),
SizedBox(
height: 120,
child: ListView.builder(
itemCount: _savedAmounts.length,
itemBuilder: (context, index) {
final amount = _savedAmounts[index];
return ListTile(
contentPadding: EdgeInsets.zero,
leading: Radio<int>(
value: amount,
groupValue: _savedAmounts.first,
onChanged: (value) {
setDialogState(() {
amountsController.text = _formatWithThousandsSeparator(value!);
});
},
),
title: Text(
_formatWithThousandsSeparator(amount),
style: TextStyle(
fontFamily: tajawalFont,
fontWeight: FontWeight.w600,
),
),
trailing: IconButton(
icon: Icon(
Icons.delete_outline,
color: Theme.of(context).colorScheme.error,
),
onPressed: () {
setDialogState(() {
_savedAmounts.remove(amount);
if (_savedAmounts.isNotEmpty) {
amountsController.text =
_formatWithThousandsSeparator(_savedAmounts.first);
} else {
amountsController.clear();
}
});
},
),
);
},
),
),
],
),
),
const SizedBox(height: 20),
TextField(
controller: amountsController,
keyboardType: TextInputType.number,
inputFormatters: [ThousandsSeparatorInputFormatter()],
decoration: InputDecoration(
labelText: 'أو أدخل مبلغًا جديدًا',
filled: true,
fillColor: Colors.grey.withOpacity(0.15),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: BorderSide.none,
),
suffixIcon: IconButton(
icon: Icon(
Icons.add_circle_rounded,
color: isValidInput(amountsController.text)
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurface.withOpacity(0.3),
size: 28,
),
onPressed: isValidInput(amountsController.text)
? () {
addAmount(amountsController.text, setDialogState);
}
: null,
),
),
onChanged: (value) { setDialogState(() {}); },
onSubmitted: (value) { addAmount(value, setDialogState); },
),
],
),
),
);
نقاط مهمة:
لا تستخدم Expanded في الـ content الخاص بـ AlertDialog مباشرة.
استخدام SingleChildScrollView مع ConstrainedBox يسمح بمحتوى قابل للتمرير بحجم محدود.
في حالة الطول الزائد للـ list أو لوحة المفاتيح، سيظهر تمرير بدل ظهور overflow.
اذا أردت نسخة متكاملة مع هذا التعديل: dart Copy code
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
elevation: 8,
insetPadding: const EdgeInsets.all(20),
titlePadding: EdgeInsets.zero,
contentPadding: const EdgeInsets.fromLTRB(24, 20, 24, 24),
title: Padding(
padding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(
Icons.monetization_on_rounded,
size: 28,
color: Theme.of(context).colorScheme.primary,
),
),
const SizedBox(width: 12),
Text(
'المحفظة الرقمية',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurface,
),
),
],
),
),
content: StatefulBuilder(
builder: (context, setDialogState) {
void addAmount(String value, void Function(void Function()) setState) {
final raw = value.replaceAll(',', '').trim();
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
amountsController.clear();
});
}
bool isValidInput(String text) {
final raw = text.replaceAll(',', '').trim();
final numAmount = int.tryParse(raw);
return numAmount != null && numAmount > 0 && !_savedAmounts.contains(numAmount);
}
final maxHeight = MediaQuery.of(context).size.height * 0.5;
return ConstrainedBox(
constraints: BoxConstraints(
maxHeight: maxHeight,
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.1),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Theme.of(context).colorScheme.outline.withOpacity(0.1),
),
),
child: _savedAmounts.isEmpty
? Column(
children: [
Icon(
Icons.wallet_rounded,
size: 40,
color: Theme.of(context).colorScheme.primary.withOpacity(0.5),
),
const SizedBox(height: 12),
Text(
'أضف المبالغ التي تريد استخدامها بشكل متكرر',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
fontSize: 14,
),
textAlign: TextAlign.center,
),
],
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'اختر من المبالغ المحفوظة:',
style: TextStyle(
fontFamily: tajawalFont,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 12),
SizedBox(
height: 120,
child: ListView.builder(
itemCount: _savedAmounts.length,
itemBuilder: (context, index) {
final amount = _savedAmounts[index];
return ListTile(
contentPadding: EdgeInsets.zero,
leading: Radio<int>(
value: amount,
groupValue: _savedAmounts.first,
onChanged: (value) {
setDialogState(() {
amountsController.text = _formatWithThousandsSeparator(value!);
});
},
),
title: Text(
_formatWithThousandsSeparator(amount),
style: TextStyle(
fontFamily: tajawalFont,
fontWeight: FontWeight.w600,
),
),
trailing: IconButton(
icon: Icon(
Icons.delete_outline,
color: Theme.of(context).colorScheme.error,
),
onPressed: () {
setDialogState(() {
_savedAmounts.remove(amount);
if (_savedAmounts.isNotEmpty) {
amountsController.text =
_formatWithThousandsSeparator(_savedAmounts.first);
} else {
amountsController.clear();
}
});
},
),
);
},
),
),
],
),
),
const SizedBox(height: 20),
TextField(
controller: amountsController,
keyboardType: TextInputType.number,
inputFormatters: [ThousandsSeparatorInputFormatter()],
decoration: InputDecoration(
labelText: 'أو أدخل مبلغًا جديدًا',
filled: true,
fillColor: Colors.grey.withOpacity(0.15),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(14),
borderSide: BorderSide.none,
),
suffixIcon: IconButton(
icon: Icon(
Icons.add_circle_rounded,
color: isValidInput(amountsController.text)
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onSurface.withOpacity(0.3),
size: 28,
),
onPressed: isValidInput(amountsController.text)
? () {
addAmount(amountsController.text, setDialogState);
}
: null,
),
),
onChanged: (value) {
setDialogState(() {});
},
onSubmitted: (value) {
addAmount(value, setDialogState);
},
),
],
),
),
);
},
),
actionsPadding: const EdgeInsets.fromLTRB(24, 0, 24, 24),
actionsAlignment: MainAxisAlignment.end,
actions: [
OutlinedButton(
onPressed: () => Navigator.pop(context),
style: OutlinedButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.onSurface,
side: BorderSide(
color: Theme.of(context).colorScheme.outline.withOpacity(0.4),
),
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'تخطي',
style: TextStyle(
fontFamily: tajawalFont,
fontSize: 15,
),
),
),
const SizedBox(width: 12),
ElevatedButton(
onPressed: () async {
if (_savedAmounts.isEmpty) {
_showSnackBar('الرجاء إدخال مبلغ واحد على الأقل');
return;
}
await _saveSavedAmounts();
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'حفظ',
style: TextStyle(
fontFamily: tajawalFont,
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
),
],
);
},
);
جرب هذا التعديل وإذا بقيت المشكلة أخبرني لأساعدك بالمزيد.