import 'package:flutter/material.dart'; import 'package:pshared/models/payment/type.dart'; import 'package:pweb/models/wallet.dart'; import 'package:pweb/pages/payment_methods/icon.dart'; import 'package:pweb/generated/i18n/app_localizations.dart'; class PaymentMethodDropdown extends StatefulWidget { final List methods; final ValueChanged onChanged; final Wallet? initialValue; const PaymentMethodDropdown({ super.key, required this.methods, required this.onChanged, this.initialValue, }); @override State createState() => _PaymentMethodDropdownState(); } class _PaymentMethodDropdownState extends State { late Wallet _selectedMethod; @override void initState() { super.initState(); _selectedMethod = widget.initialValue ?? widget.methods.first; } @override Widget build(BuildContext context) { return DropdownButtonFormField( dropdownColor: Theme.of(context).colorScheme.onSecondary, initialValue: _selectedMethod, decoration: InputDecoration( labelText: AppLocalizations.of(context)!.whereGetMoney, border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)), ), items: widget.methods.map((method) { return DropdownMenuItem( value: method, child: Row( children: [ Icon(iconForPaymentType(PaymentType.managedWallet), size: 20), const SizedBox(width: 8), Text(method.name), ], ), ); }).toList(), onChanged: (value) { if (value != null) { setState(() => _selectedMethod = value); widget.onChanged(value); } }, ); } }