fix payment card change. fix adding a new payment card
This commit is contained in:
@@ -27,6 +27,7 @@ class PaymentMethodSheet extends StatefulWidget {
|
||||
|
||||
class _PaymentMethodSheetState extends State<PaymentMethodSheet> {
|
||||
int? _selectedPaymentMethod = -2;
|
||||
int? _processingCardId; // <-- Переменная для отслеживания отправленного запроса
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -36,56 +37,20 @@ class _PaymentMethodSheetState extends State<PaymentMethodSheet> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<PaymentMethodSheetBloc, PaymentMethodSheetState>(
|
||||
return BlocConsumer<PaymentMethodSheetBloc, PaymentMethodSheetState>(
|
||||
listener: (context, state) {
|
||||
if (state.status == PaymentMethodSheetStatus.success && _processingCardId != null) {
|
||||
final updatedCard = state.cards.cast<PaymentCard?>().firstWhere(
|
||||
(c) => c?.id == _processingCardId,
|
||||
orElse: () => state.cards.cast<PaymentCard?>().firstWhere((c) => c?.isMain == true, orElse: () => null),
|
||||
);
|
||||
|
||||
_processingCardId = null;
|
||||
Navigator.pop(context, updatedCard);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
|
||||
if (state.status == PaymentMethodSheetStatus.loading) {
|
||||
return Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(30)),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 20, sigmaY: 20),
|
||||
child: Container(
|
||||
height: 450,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0x00000032).withOpacity(0.6),
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(30)),
|
||||
),
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state.status == PaymentMethodSheetStatus.failure) {
|
||||
return Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(30)),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 20, sigmaY: 20),
|
||||
child: Container(
|
||||
height: 450,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0x00000032).withOpacity(0.6),
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(30)),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
state.errorMessage ?? 'Ошибка загрузки карт',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state.status == PaymentMethodSheetStatus.success && _selectedPaymentMethod == -2) {
|
||||
if (widget.initialSelectedCard != null) {
|
||||
final initialIndex = state.cards.indexWhere(
|
||||
@@ -98,14 +63,6 @@ class _PaymentMethodSheetState extends State<PaymentMethodSheet> {
|
||||
}
|
||||
}
|
||||
|
||||
// Находим карту с isMain: true при загрузке
|
||||
/*if (_selectedPaymentMethod == null) {
|
||||
final mainCardIndex = state.cards.indexWhere((card) => card.isMain);
|
||||
if (mainCardIndex != -1) {
|
||||
_selectedPaymentMethod = mainCardIndex;
|
||||
}
|
||||
}*/
|
||||
|
||||
return Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: ClipRRect(
|
||||
@@ -122,47 +79,6 @@ class _PaymentMethodSheetState extends State<PaymentMethodSheet> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.pop(context),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.arrow_back_ios_sharp,
|
||||
color: const Color(0x99FFFFFF),
|
||||
size: 20,
|
||||
),
|
||||
Icon(
|
||||
Icons.arrow_back_ios_sharp,
|
||||
color: const Color(0x66FFFFFF),
|
||||
size: 20,
|
||||
),
|
||||
Icon(
|
||||
Icons.arrow_back_ios_sharp,
|
||||
color: const Color(0x22FFFFFF),
|
||||
size: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Выберите способ оплаты',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
@@ -198,13 +114,14 @@ class _PaymentMethodSheetState extends State<PaymentMethodSheet> {
|
||||
onTap: () async {
|
||||
setState(() {
|
||||
_selectedPaymentMethod = index;
|
||||
_processingCardId = card.id;
|
||||
});
|
||||
|
||||
// Отправляем событие в Блок
|
||||
context.read<PaymentMethodSheetBloc>().add(
|
||||
SelectPaymentCardRequested(card),
|
||||
);
|
||||
|
||||
Navigator.pop(context, card);
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -223,8 +140,7 @@ class _PaymentMethodSheetState extends State<PaymentMethodSheet> {
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
context.go('/home/payment-methods/add-card');
|
||||
context.read<PaymentMethodSheetBloc>().add(AddPaymentCardRequested());
|
||||
},
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
child: Center(
|
||||
|
||||
@@ -324,7 +324,6 @@ class _TariffSheetState extends State<TariffSheet> {
|
||||
getIt<SetMainPaymentCardUsecase>(),
|
||||
getIt<GetProfileUseCase>(),
|
||||
getIt<AddPaymentCardUsecase>(),
|
||||
|
||||
)..add(PaymentMethodSheetStarted()),
|
||||
child: PaymentMethodSheet(
|
||||
initialSelectedCard: state.useBalance ? null : state.selectedCard,
|
||||
|
||||
Reference in New Issue
Block a user