turns-00082.parquet:1450
5d225ba4513d22131d5b05cc
turn 1/8gpt-4.1-mini-2025-04-14EnglishYemen796 words
degenerate_repetitionAbsentFinal dense release
USER
اريد ان يتم تفريغ حقل او ادخل مبلغ جديد بعد اضافة المبلغ عبر ايقونة الاضافة
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,
),
),
),
],
),
],
),
),
),
);
},
);
},
);
ASSISTANT
يمكنك تعديل جزء إضافة المبلغ بحيث يتم تفريغ الحقل بعد إضافة المبلغ مباشرة، وذلك باستخدام `setState` مع تفريغ الحقل، أو تفريغ الحقل خارج `setState` مع تحديث الواجهة بشكل صحيح.
في الكود الذي أرفقته، أنت تفريغ الحقل (`amountsController.clear()`) بعد الـ `setState`، وهذا صحيح، لكن يمكنك تحسين السلوك عند إضافة المبلغ كالتالي:
### التعديل المقترح:
قم بوضع تفريغ الحقل `amountsController.clear()` داخل الـ `setState` لكي يتم تحديث الشاشة (وليس خارجها)، وذلك هكذا:
```dart
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
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`. تأكد أن هذا لا يتسبب بتضارب مع التحديثات المتكررة.
إذا تحتاج مثال كامل للجزء المعدل فقط أو توضيحات إضافية لا تتردد بالسؤال.