code Copy code
// 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.15),
),
),
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,
),
),
),
],
),
],
),
),
),
);
},
);
},
);
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return StatefulBuilder(
builder: (context, setDialogState) {
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: [
// العنوان مع الأيقونة
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),
// قائمة المبالغ المحفوظة
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.15),
),
),
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,
),
],
)
: SizedBox(
height: 150,
child: ListView.builder(
itemCount: _savedAmounts.length,
itemBuilder: (context, index) {
final amt = _savedAmounts[index];
return ListTile(
contentPadding: EdgeInsets.zero,
leading: Radio<int>(
value: amt,
groupValue: int.tryParse(amountsController.text.replaceAll(',', '')) ?? -1,
onChanged: (value) {
setDialogState(() {
amountsController.text = _formatWithThousandsSeparator(value!);
});
},
),
title: Text(
_formatWithThousandsSeparator(amt),
style: const TextStyle(
fontFamily: tajawalFont,
fontWeight: FontWeight.w600,
),
),
trailing: IconButton(
icon: Icon(
Icons.delete_outline,
color: Theme.of(context).colorScheme.error,
),
tooltip: 'حذف هذا المبلغ',
onPressed: () {
setDialogState(() {
_savedAmounts.removeAt(index);
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: 'أو أدخل مبلغًا جديدًا',
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,
),
tooltip: 'إضافة المبلغ',
onPressed: () {
final raw = amountsController.text.replaceAll(',', '');
final numAmount = int.tryParse(raw);
if (numAmount == null || numAmount <= 0) {
_showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
return;
}
if (_savedAmounts.contains(numAmount)) {
_showSnackBar('هذا المبلغ موجود بالفعل');
return;
}
setDialogState(() {
_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;
}
setDialogState(() {
_savedAmounts.add(numAmount);
_savedAmounts.sort();
amountsController.clear();
});
},
),
const SizedBox(height: 24),
// أزرار الإجراء
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);
_showSnackBar('تم حفظ المبالغ بنجاح');
},
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,
),
),
),
],
),
],
),
),
),
);
},
);
},
);