اريد تحسين التصميم هنا
ولا اريد استخدام صور للشركات
واريد اضافة قائمة لعرض جهات الاتصال التي تم تحديدها بشكل افضل واريد اضافة  اسلوب لازالة جهه الاتصال واريد اضافة قائمة منفضلة قبل بدا استخدام البرنامج يقوم باخبار المستخدم بادخال المبالغ المراد تحويلها  واريد
مع اضافة اسلوب لتعديل المبالغ المحفوظة او ازالتها
للعلم عند اضافة جهه  الاتصال اريد ان يكون اضافة المبلغ عبارة عن تحديد المبلغ من المبالغ التي تم حفظها
الكود
import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:telephony/telephony.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:url_launcher/url_launcher.dart';

void main() => runApp(SMSApp());

void onBackgroundMessage(SmsMessage message) {
  debugPrint("رسالة واردة في الخلفية: ${message.body}");
}

class SMSApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'تحويل رصيد متعدد',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
          seedColor: const Color(0xFF1A73E8),
          primary: const Color(0xFF1A73E8),
          secondary: const Color(0xFF4285F4),
          tertiary: const Color(0xFF34A853),
          background: const Color(0xFFF8F9FA),
          surface: Colors.white,
          onPrimary: Colors.white,
          onSecondary: Colors.white,
          onBackground: const Color(0xFF202124),
          onSurface: const Color(0xFF202124),
        ),
        useMaterial3: true,
        fontFamily: 'Tajawal',
        appBarTheme: AppBarTheme(
          backgroundColor: const Color(0xFF1A73E8),
          foregroundColor: Colors.white,
          elevation: 0,
          centerTitle: true,
          titleTextStyle: const TextStyle(
            fontSize: 20,
            fontWeight: FontWeight.bold,
          ),
          iconTheme: const IconThemeData(color: Colors.white),
        ),
        cardTheme: CardTheme(
          color: Colors.white,
          elevation: 2,
          margin: const EdgeInsets.all(8),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(16),
          ),
          surfaceTintColor: Colors.white,
        ),
        elevatedButtonTheme: ElevatedButtonThemeData(
          style: ElevatedButton.styleFrom(
            backgroundColor: const Color(0xFF1A73E8),
            foregroundColor: Colors.white,
            padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(12),
            ),
            elevation: 0,
            textStyle: const TextStyle(
              fontWeight: FontWeight.w600,
              fontSize: 16,
            ),
          ),
        ),
        outlinedButtonTheme: OutlinedButtonThemeData(
          style: OutlinedButton.styleFrom(
            padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(12),
            ),
            side: const BorderSide(width: 1.5, color: Color(0xFF1A73E8)),
            textStyle: const TextStyle(fontWeight: FontWeight.w600),
          ),
        ),
        textButtonTheme: TextButtonThemeData(
          style: TextButton.styleFrom(
            foregroundColor: const Color(0xFF1A73E8),
            textStyle: const TextStyle(fontWeight: FontWeight.w600),
          ),
        ),
        snackBarTheme: SnackBarThemeData(
          behavior: SnackBarBehavior.floating,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(12),
          ),
          backgroundColor: const Color(0xFF1A73E8),
          contentTextStyle: const TextStyle(color: Colors.white),
        ),
        inputDecorationTheme: InputDecorationTheme(
          filled: true,
          fillColor: Colors.grey.shade50,
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(12),
            borderSide: BorderSide.none,
          ),
          focusedBorder: OutlineInputBorder(
            borderRadius: BorderRadius.circular(12),
            borderSide: const BorderSide(color: Color(0xFF1A73E8), width: 2),
          ),
          contentPadding: const EdgeInsets.symmetric(
            horizontal: 16,
            vertical: 14,
          ),
        ),
        dialogTheme: DialogTheme(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(20),
          ),
          backgroundColor: Colors.white,
          elevation: 8,
          surfaceTintColor: Colors.white,
        ),
        listTileTheme: ListTileThemeData(
          iconColor: const Color(0xFF1A73E8),
          contentPadding: const EdgeInsets.symmetric(horizontal: 16),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(12),
          ),
        ),
        dividerTheme: DividerThemeData(
          color: Colors.grey.shade200,
          thickness: 1,
          space: 0,
        ),
        progressIndicatorTheme: const ProgressIndicatorThemeData(
          color: Color(0xFF1A73E8),
        ),
        chipTheme: ChipThemeData(
          backgroundColor: Colors.grey.shade100,
          selectedColor: const Color(0xFF1A73E8),
          secondarySelectedColor: const Color(0xFF1A73E8),
          disabledColor: Colors.grey.shade300,
          labelStyle: const TextStyle(color: Colors.black),
          secondaryLabelStyle: const TextStyle(color: Colors.white),
          brightness: Brightness.light,
          padding: EdgeInsets.symmetric(horizontal: 12, vertical: 4),
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
        ),
      ),
      home: SMSHomePage(),
    );
  }
}

class TransferItem {
  String number;
  int amount;
  String? pin;

  TransferItem({required this.number, required this.amount, this.pin});

  Map<String, dynamic> toMap() {
    return {'number': number, 'amount': amount, 'pin': pin};
  }

  factory TransferItem.fromMap(Map<String, dynamic> map) {
    return TransferItem(
      number: map['number'],
      amount: map['amount'],
      pin: map['pin'],
    );
  }
}

class SMSHomePage extends StatefulWidget {
  @override
  _SMSHomePageState createState() => _SMSHomePageState();
}

class _SMSHomePageState extends State<SMSHomePage> with WidgetsBindingObserver {
  final Telephony _telephony = Telephony.instance;
  SharedPreferences? _prefs;

  List<TransferItem> _transferList = [];
  String _selectedMethod = 'yemenMobile';
  bool _isTransferring = false;
  List<Map<String, dynamic>> _transferLogs = [];
  List<String> _savedNumbers = [];

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
    _initApp();
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  Future<void> _initApp() async {
    _prefs = await SharedPreferences.getInstance();
    List<String>? savedTransfers = _prefs?.getStringList('transferList');

    if (savedTransfers != null && savedTransfers.isNotEmpty) {
      _transferList =
          savedTransfers
              .map(
                (e) => TransferItem.fromMap(
                  json.decode(e) as Map<String, dynamic>,
                ),
              )
              .toList();
    } else {
      _transferList = [];
    }

    _selectedMethod = _prefs?.getString('selectedMethod') ?? 'yemenMobile';
    _savedNumbers = _prefs?.getStringList('savedNumbers') ?? [];
    await _requestPermissions();

    if (mounted) setState(() {});
  }

  Future<bool> _requestPermissions() async {
    final phoneStatus = await Permission.phone.status;
    final contactsStatus = await Permission.contacts.status;

    if (!phoneStatus.isGranted || !contactsStatus.isGranted) {
      final status = await [Permission.phone, Permission.contacts].request();

      if (!status[Permission.phone]!.isGranted ||
          !status[Permission.contacts]!.isGranted) {
        _showSnackBar(
          'يجب منح أذونات المكالمات وجهات الاتصال لاستخدام التطبيق',
        );
        return false;
      }
    }
    return true;
  }

  Future<void> _saveTransferList() async {
    final list = _transferList.map((e) => json.encode(e.toMap())).toList();
    await _prefs?.setStringList('transferList', list);
  }

  Future<void> _saveSelectedMethod() async {
    await _prefs?.setString('selectedMethod', _selectedMethod);
  }

  Future<void> _saveSavedNumbers() async {
    await _prefs?.setStringList('savedNumbers', _savedNumbers);
  }

  void _showSnackBar(String msg) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text(msg),
        behavior: SnackBarBehavior.floating,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
      ),
    );
  }

  void _showSavedNumbersSelection() async {
    final hasPermission = await _requestPermissions();
    if (!hasPermission) return;

    final contacts = await FlutterContacts.getContacts(
      withProperties: true,
      withThumbnail: false,
    );

    List<String> selectedNumbers = List.from(_savedNumbers);

    showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      builder: (context) {
        return Container(
          decoration: BoxDecoration(
            color: Theme.of(context).colorScheme.surface,
            borderRadius: const BorderRadius.vertical(top: Radius.circular(24)),
          ),
          padding: EdgeInsets.only(
            bottom: MediaQuery.of(context).viewInsets.bottom,
          ),
          child: StatefulBuilder(
            builder: (context, setModal) {
              return Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Padding(
                    padding: const EdgeInsets.all(16),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          'اختر أرقام من جهات الاتصال',
                          style: TextStyle(
                            fontSize: 18,
                            fontWeight: FontWeight.bold,
                            color: Theme.of(context).colorScheme.onSurface,
                          ),
                        ),
                        IconButton(
                          icon: Icon(
                            Icons.close,
                            color: Theme.of(context).colorScheme.onSurface,
                          ),
                          onPressed: () => Navigator.pop(context),
                        ),
                      ],
                    ),
                  ),
                  const Divider(height: 1),
                  Expanded(
                    child: ListView.builder(
                      shrinkWrap: true,
                      itemCount: contacts.length,
                      itemBuilder: (context, index) {
                        final contact = contacts[index];
                        final phones =
                            contact.phones.map((e) => e.number).toList();

                        return ExpansionTile(
                          title: Text(
                            contact.displayName,
                            style: TextStyle(
                              color: Theme.of(context).colorScheme.onSurface,
                            ),
                          ),
                          children:
                              phones.map((phone) {
                                final normalized = phone.replaceAll(
                                  RegExp(r'[^\d+]'),
                                  '',
                                );

                                final isSelected = selectedNumbers.any((num) {
                                  String n = num.replaceAll(
                                    RegExp(r'[^\d+]'),
                                    '',
                                  );
                                  return n == normalized;
                                });

                                return CheckboxListTile(
                                  value: isSelected,
                                  title: Text(phone),
                                  onChanged: (val) {
                                    setModal(() {
                                      if (val == true) {
                                        if (!selectedNumbers.any((num) {
                                          final n = num.replaceAll(
                                            RegExp(r'[^\d+]'),
                                            '',
                                          );
                                          return n == normalized;
                                        })) {
                                          selectedNumbers.add(phone);
                                        }
                                      } else {
                                        selectedNumbers.removeWhere((num) {
                                          final n = num.replaceAll(
                                            RegExp(r'[^\d+]'),
                                            '',
                                          );
                                          return n == normalized;
                                        });
                                      }
                                    });
                                  },
                                );
                              }).toList(),
                        );
                      },
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(16),
                    child: Row(
                      children: [
                        Expanded(
                          child: OutlinedButton(
                            onPressed: () => Navigator.pop(context),
                            child: const Text('إلغاء'),
                          ),
                        ),
                        const SizedBox(width: 12),
                        Expanded(
                          child: ElevatedButton(
                            onPressed: () async {
                              _savedNumbers = List.from(selectedNumbers);
                              await _saveSavedNumbers();
                              Navigator.pop(context);
                              _showSnackBar('تم حفظ الأرقام المختارة');
                            },
                            child: const Text('حفظ'),
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              );
            },
          ),
        );
      },
    );
  }

  void _addTransfersFromSavedNumbers() {
    for (var number in _savedNumbers) {
      if (!_transferList.any((element) => element.number == number)) {
        _transferList.add(TransferItem(number: number, amount: 0, pin: '1234'));
      }
    }
    setState(() {});
  }

  void _removeTransferAt(int index) {
    setState(() {
      _transferList.removeAt(index);
    });
    _saveTransferList();
  }

  void _editTransfer(int index) {
    var item = _transferList[index];
    final amountController = TextEditingController(
      text: item.amount.toString(),
    );
    final pinController = TextEditingController(text: item.pin ?? '1234');

    showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      builder: (context) {
        return Container(
          decoration: BoxDecoration(
            color: Theme.of(context).colorScheme.surface,
            borderRadius: const BorderRadius.vertical(top: Radius.circular(24)),
          ),
          padding: EdgeInsets.only(
            bottom: MediaQuery.of(context).viewInsets.bottom,
          ),
          child: SingleChildScrollView(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Padding(
                  padding: const EdgeInsets.all(16),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        "تعديل التحويل",
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                          fontSize: 18,
                          color: Theme.of(context).colorScheme.onSurface,
                        ),
                      ),
                      IconButton(
                        icon: Icon(
                          Icons.close,
                          color: Theme.of(context).colorScheme.onSurface,
                        ),
                        onPressed: () => Navigator.pop(context),
                      ),
                    ],
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 16),
                  child: Text(
                    item.number,
                    style: TextStyle(
                      color: Theme.of(
                        context,
                      ).colorScheme.onSurface.withOpacity(0.7),
                    ),
                  ),
                ),
                const Divider(height: 24),
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 16),
                  child: TextField(
                    controller: amountController,
                    keyboardType: TextInputType.number,
                    decoration: InputDecoration(
                      labelText: "المبلغ / عدد الوحدات",
                      prefixIcon: Icon(Icons.monetization_on_outlined),
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(12),
                      ),
                    ),
                  ),
                ),
                if (_selectedMethod == 'yemenMobile' ||
                    _selectedMethod == 'sabafon')
                  Padding(
                    padding: const EdgeInsets.fromLTRB(16, 16, 16, 24),
                    child: TextField(
                      controller: pinController,
                      keyboardType: TextInputType.number,
                      decoration: InputDecoration(
                        labelText: "الرقم السري",
                        prefixIcon: Icon(Icons.lock_outline),
                        border: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(12),
                        ),
                      ),
                      obscureText: true,
                    ),
                  ),
                Padding(
                  padding: const EdgeInsets.all(16),
                  child: Row(
                    children: [
                      Expanded(
                        child: OutlinedButton(
                          onPressed: () => Navigator.pop(context),
                          child: const Text("إلغاء"),
                        ),
                      ),
                      const SizedBox(width: 12),
                      Expanded(
                        child: ElevatedButton(
                          onPressed: () {
                            final amountStr = amountController.text.trim();
                            final pinStr = pinController.text.trim();

                            final intAmount = int.tryParse(amountStr);
                            if (intAmount == null || intAmount <= 0) {
                              _showSnackBar('يرجى إدخال مبلغ صحيح أكبر من صفر');
                              return;
                            }
                            setState(() {
                              _transferList[index].amount = intAmount;
                              if (_selectedMethod == 'yemenMobile' ||
                                  _selectedMethod == 'sabafon') {
                                _transferList[index].pin =
                                    pinStr.isEmpty ? '1234' : pinStr;
                              } else {
                                _transferList[index].pin = null;
                              }
                            });
                            _saveTransferList();
                            Navigator.pop(context);
                          },
                          child: const Text("حفظ"),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  String _buildUssdCode(TransferItem item) {
    final number = item.number;
    final amount = item.amount.toString();
    final pin = item.pin ?? '1234';

    switch (_selectedMethod) {
      case 'yemenMobile':
        return '*888*$amount*$number*$pin#';
      case 'y':
        return '*109*$amount*$number#';
      case 'sabafon':
        return '*123*$pin*$number*$amount#';
      case 'you':
        return '*130*$number*$amount#';
      default:
        return '';
    }
  }

  Future<void> _startTransferSequence() async {
    if (_transferList.isEmpty) {
      _showSnackBar("لا توجد معاملات للتحويل");
      return;
    }

    if (!await Permission.phone.isGranted) {
      final status = await Permission.phone.request();
      if (!status.isGranted) {
        _showSnackBar("يجب منح إذن الاتصال لإجراء تحويل الرصيد");
        return;
      }
    }

    setState(() => _isTransferring = true);
    _transferLogs.clear();

    for (var i = 0; i < _transferList.length; i++) {
      var item = _transferList[i];
      String ussdCode = _buildUssdCode(item);
      final encodedUssd = Uri.encodeComponent(ussdCode);
      final Uri uri = Uri.parse('tel:$encodedUssd');

      _showSnackBar(
        'جاري تحويل ${_getMethodName(_selectedMethod)}: ${item.amount} إلى ${item.number} (${i + 1}/${_transferList.length})',
      );

      try {
        if (await canLaunchUrl(uri)) {
          await launchUrl(uri);
          _transferLogs.add({
            'number': item.number,
            'amount': item.amount,
            'success': true,
            'method': _selectedMethod,
          });
        } else {
          _transferLogs.add({
            'number': item.number,
            'amount': item.amount,
            'success': false,
            'method': _selectedMethod,
            'error': 'تعذر تشغيل رمز USSD',
          });
        }
      } catch (e) {
        _transferLogs.add({
          'number': item.number,
          'amount': item.amount,
          'success': false,
          'method': _selectedMethod,
          'error': e.toString(),
        });
      }

      // تأخير لتجنب تداخل الطلبات
      await Future.delayed(const Duration(seconds: 5));
    }

    setState(() => _isTransferring = false);
    _showSnackBar("تمت جميع عمليات التحويل");
  }

  String _getMethodName(String method) {
    switch (method) {
      case 'yemenMobile':
        return 'يمن موبايل';
      case 'y':
        return 'واي';
      case 'sabafon':
        return 'سبأفون';
      case 'you':
        return 'يو';
      default:
        return method;
    }
  }

  void _showTransferLogsDialog() {
    showDialog(
      context: context,
      builder: (context) {
        return Dialog(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(20),
          ),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Padding(
                padding: const EdgeInsets.all(16),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      'سجل عمليات التحويل',
                      style: TextStyle(
                        fontSize: 18,
                        fontWeight: FontWeight.bold,
                        color: Theme.of(context).colorScheme.onSurface,
                      ),
                    ),
                    IconButton(
                      icon: Icon(Icons.close),
                      onPressed: () => Navigator.pop(context),
                    ),
                  ],
                ),
              ),
              const Divider(height: 1),
              SizedBox(
                height: 300,
                width: double.maxFinite,
                child:
                    _transferLogs.isEmpty
                        ? Center(
                          child: Text(
                            'لا توجد عمليات تحويل حتى الآن',
                            style: TextStyle(
                              color: Theme.of(
                                context,
                              ).colorScheme.onSurface.withOpacity(0.6),
                            ),
                          ),
                        )
                        : ListView.builder(
                          itemCount: _transferLogs.length,
                          itemBuilder: (_, i) {
                            final log = _transferLogs[i];
                            final success = log['success'] as bool;
                            return ListTile(
                              leading: Container(
                                width: 36,
                                height: 36,
                                decoration: BoxDecoration(
                                  color:
                                      success
                                          ? Colors.green.shade50
                                          : Colors.red.shade50,
                                  shape: BoxShape.circle,
                                ),
                                child: Icon(
                                  success ? Icons.check : Icons.error,
                                  color: success ? Colors.green : Colors.red,
                                ),
                              ),
                              title: Text(
                                '${_getMethodName(log['method'])} - ${log['number']}',
                                style: TextStyle(
                                  fontWeight: FontWeight.w500,
                                  color:
                                      Theme.of(context).colorScheme.onSurface,
                                ),
                              ),
                              subtitle: Text(
                                'المبلغ: ${log['amount']}',
                                style: TextStyle(
                                  color: Theme.of(
                                    context,
                                  ).colorScheme.onSurface.withOpacity(0.6),
                                ),
                              ),
                              trailing:
                                  !success
                                      ? Tooltip(
                                        message:
                                            log['error'] ?? 'خطأ غير معروف',
                                        child: Icon(
                                          Icons.info_outline,
                                          color: Colors.red,
                                        ),
                                      )
                                      : null,
                            );
                          },
                        ),
              ),
              Padding(
                padding: const EdgeInsets.all(16),
                child: ElevatedButton(
                  onPressed: () => Navigator.pop(context),
                  child: const Text('إغلاق'),
                ),
              ),
            ],
          ),
        );
      },
    );
  }

  // الجزء الأهم مع التعديل لتجنب الـ overflow وظهور الصور

  Widget _buildTransferMethodMenu() {
    // تعيين القائمة مع items في القائمة المنبثقة
    return PopupMenuButton<String>(
      icon: const Icon(Icons.compare_arrows),
      tooltip: 'طريقة التحويل',
      onSelected: (value) async {
        setState(() => _selectedMethod = value);
        await _saveSelectedMethod();
        if (_selectedMethod == 'yemenMobile' || _selectedMethod == 'sabafon') {
          for (var item in _transferList) {
            item.pin ??= '1234';
          }
        } else {
          for (var item in _transferList) {
            item.pin = null;
          }
        }
        setState(() {});
      },
      itemBuilder:
          (_) => [
            PopupMenuItem(
              value: 'yemenMobile',
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Image.asset(
                    'assets/yemenmobile.png',
                    width: 24,
                    height: 24,
                    fit: BoxFit.contain,
                  ),
                  const SizedBox(width: 12),
                  Flexible(
                    child: const Text(
                      'يمن موبايل',
                      overflow: TextOverflow.ellipsis,
                    ),
                  ),
                ],
              ),
            ),
            PopupMenuItem(
              value: 'y',
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Image.asset(
                    'assets/y.png',
                    width: 24,
                    height: 24,
                    fit: BoxFit.contain,
                  ),
                  const SizedBox(width: 12),
                  Flexible(
                    child: const Text('واي', overflow: TextOverflow.ellipsis),
                  ),
                ],
              ),
            ),
            PopupMenuItem(
              value: 'sabafon',
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Image.asset(
                    'assets/sabafon.png',
                    width: 24,
                    height: 24,
                    fit: BoxFit.contain,
                  ),
                  const SizedBox(width: 12),
                  Flexible(
                    child: const Text(
                      'سبأفون',
                      overflow: TextOverflow.ellipsis,
                    ),
                  ),
                ],
              ),
            ),
            PopupMenuItem(
              value: 'you',
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Image.asset(
                    'assets/you.png',
                    width: 24,
                    height: 24,
                    fit: BoxFit.contain,
                  ),
                  const SizedBox(width: 12),
                  Flexible(
                    child: const Text('يو', overflow: TextOverflow.ellipsis),
                  ),
                ],
              ),
            ),
          ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('تحويل رصيد متعدد'),
        actions: [
          IconButton(
            icon: const Icon(Icons.contacts),
            tooltip: 'إدارة الأرقام المحفوظة',
            onPressed: _showSavedNumbersSelection,
          ),

          // هنا استبدلت PopupMenuButton مباشرة بدالة معاد استخدامها
          _buildTransferMethodMenu(),
        ],
      ),
      floatingActionButton: FloatingActionButton.extended(
        icon: const Icon(Icons.send_rounded),
        label:
            _isTransferring
                ? Row(
                  mainAxisSize: MainAxisSize.min,
                  children: const [
                    SizedBox(
                      width: 20,
                      height: 20,
                      child: CircularProgressIndicator(
                        color: Colors.white,
                        strokeWidth: 2,
                      ),
                    ),
                    SizedBox(width: 8),
                    Text('جار التحويل...'),
                  ],
                )
                : const Text('إجراء التحويلات'),
        onPressed: _isTransferring ? null : _startTransferSequence,
      ),
      body: Column(
        children: [
          Card(
            margin: const EdgeInsets.all(12),
            child: Padding(
              padding: const EdgeInsets.all(16),
              child: Column(
                children: [
                  Row(
                    children: [
                      Icon(
                        Icons.info_outline,
                        color: Theme.of(context).colorScheme.primary,
                      ),
                      const SizedBox(width: 8),
                      Text(
                        'طريقة التحويل الحالية',
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                          color: Theme.of(context).colorScheme.onSurface,
                        ),
                      ),
                    ],
                  ),
                  const SizedBox(height: 8),
                  Text(
                    _getMethodName(_selectedMethod),
                    style: TextStyle(
                      fontSize: 16,
                      color: Theme.of(
                        context,
                      ).colorScheme.onSurface.withOpacity(0.8),
                    ),
                  ),
                  const SizedBox(height: 12),
                  ElevatedButton.icon(
                    icon: const Icon(Icons.refresh),
                    label: const Text('تحديث قائمة التحويل'),
                    onPressed: () {
                      _addTransfersFromSavedNumbers();
                      _saveTransferList();
                      _showSnackBar('تم تحديث قائمة التحويل بالأرقام المحفوظة');
                    },
                  ),
                ],
              ),
            ),
          ),
          const Divider(height: 1),
          Expanded(
            child:
                _transferList.isEmpty
                    ? Center(
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          Icon(
                            Icons.phone_iphone_outlined,
                            size: 64,
                            color: Theme.of(
                              context,
                            ).colorScheme.onSurface.withOpacity(0.3),
                          ),
                          const SizedBox(height: 16),
                          Text(
                            'لا توجد عمليات تحويل',
                            style: TextStyle(
                              fontSize: 18,
                              color: Theme.of(
                                context,
                              ).colorScheme.onSurface.withOpacity(0.6),
                            ),
                          ),
                          const SizedBox(height: 8),
                          Text(
                            'أضف الأرقام المحفوظة أولاً',
                            style: TextStyle(
                              color: Theme.of(
                                context,
                              ).colorScheme.onSurface.withOpacity(0.5),
                            ),
                          ),
                        ],
                      ),
                    )
                    : ListView.builder(
                      itemCount: _transferList.length,
                      itemBuilder: (context, index) {
                        final item = _transferList[index];
                        return Dismissible(
                          key: Key('${item.number}_$index'),
                          background: Container(
                            margin: const EdgeInsets.symmetric(
                              horizontal: 12,
                              vertical: 6,
                            ),
                            decoration: BoxDecoration(
                              color: Colors.red.shade50,
                              borderRadius: BorderRadius.circular(16),
                            ),
                            alignment: Alignment.centerRight,
                            padding: const EdgeInsets.only(right: 24),
                            child: Icon(
                              Icons.delete,
                              color: Colors.red.shade400,
                            ),
                          ),
                          onDismissed: (direction) => _removeTransferAt(index),
                          child: Card(
                            margin: const EdgeInsets.symmetric(
                              horizontal: 12,
                              vertical: 6,
                            ),
                            child: ListTile(
                              leading: Container(
                                width: 40,
                                height: 40,
                                decoration: BoxDecoration(
                                  color: Theme.of(
                                    context,
                                  ).colorScheme.primary.withOpacity(0.1),
                                  shape: BoxShape.circle,
                                ),
                                child: Icon(
                                  Icons.phone_android,
                                  color: Theme.of(context).colorScheme.primary,
                                ),
                              ),
                              title: Text(
                                item.number,
                                style: TextStyle(
                                  fontWeight: FontWeight.w500,
                                  color:
                                      Theme.of(context).colorScheme.onSurface,
                                ),
                              ),
                              subtitle: Text(
                                'المبلغ: ${item.amount}',
                                style: TextStyle(
                                  color: Theme.of(
                                    context,
                                  ).colorScheme.onSurface.withOpacity(0.6),
                                ),
                              ),
                              trailing: IconButton(
                                icon: Icon(
                                  Icons.edit,
                                  color: Theme.of(context).colorScheme.primary,
                                ),
                                onPressed: () => _editTransfer(index),
                              ),
                            ),
                          ),
                        );
                      },
                    ),
          ),
          if (_transferLogs.isNotEmpty)
            Padding(
              padding: const EdgeInsets.all(12),
              child: ElevatedButton.icon(
                icon: const Icon(Icons.history),
                label: const Text('عرض سجل التحويلات'),
                onPressed: _showTransferLogsDialog,
              ),
            ),
        ],
      ),
    );
  }
}

للعلم اريد الكود كامل لاقوم باستخدامة مباشرة