fix to prod
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../core/app_colors.dart';
|
||||
import '../../data/network/api_service.dart';
|
||||
import '../../di/service_locator.dart';
|
||||
import '../../domain/entities/payment_card.dart';
|
||||
import '../../domain/usecase/add_payment_card_usecase.dart';
|
||||
@@ -34,13 +35,20 @@ class FinePaymentScreen extends StatelessWidget {
|
||||
getFineDetailsUsecase: getIt(),
|
||||
payFineUsecase: getIt(),
|
||||
)..add(FetchFineDetails(fineId)),
|
||||
child: const _FinePaymentScreenContent(),
|
||||
child: _FinePaymentScreenContent(fineId: fineId),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FinePaymentScreenContent extends StatelessWidget {
|
||||
const _FinePaymentScreenContent();
|
||||
final int fineId;
|
||||
|
||||
const _FinePaymentScreenContent({required this.fineId});
|
||||
|
||||
String _resolveImageUrl(String path) {
|
||||
if (path.startsWith('http://') || path.startsWith('https://')) return path;
|
||||
return 'https://sharing-api.sparkit.by/$path';
|
||||
}
|
||||
|
||||
void _openFullScreenImage(BuildContext context, List<String> photos, int initialIndex) {
|
||||
Navigator.of(context).push(
|
||||
@@ -88,24 +96,30 @@ class _FinePaymentScreenContent extends StatelessWidget {
|
||||
listenWhen: (previous, current) => previous.status != current.status,
|
||||
listener: (context, state) {
|
||||
if (state.status == FinePaymentStatus.success && state.paymentCompleted) {
|
||||
context.go('/home');
|
||||
context.go('/home/fine-payment/$fineId/result/success');
|
||||
} else if (state.status == FinePaymentStatus.failure) {
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
state.errorMessage ?? 'Произошла ошибка при оплате штрафа',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
if (state.fine != null) {
|
||||
// штраф уже был загружен — значит ошибка произошла при попытке оплаты
|
||||
context.go('/home/fine-payment/$fineId/result/failed');
|
||||
} else {
|
||||
// штраф не удалось загрузить — остаёмся на месте, показываем снекбар
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
state.errorMessage ?? 'Произошла ошибка при оплате штрафа',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
backgroundColor: Colors.redAccent.withOpacity(0.9),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
margin: const EdgeInsets.all(20),
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
backgroundColor: Colors.redAccent.withOpacity(0.9),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
margin: const EdgeInsets.all(20),
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
@@ -122,6 +136,8 @@ class _FinePaymentScreenContent extends StatelessWidget {
|
||||
|
||||
if (fine == null) return const SizedBox.shrink();
|
||||
|
||||
final bool isPaid = fine.isPaid;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -136,7 +152,7 @@ class _FinePaymentScreenContent extends StatelessWidget {
|
||||
separatorBuilder: (_, __) => const SizedBox(width: 12),
|
||||
itemBuilder: (context, index) {
|
||||
final photo = fine.photoUrls[index];
|
||||
final isNetwork = photo.startsWith('http');
|
||||
final imageUrl = _resolveImageUrl(photo);
|
||||
return GestureDetector(
|
||||
onTap: () => _openFullScreenImage(
|
||||
context,
|
||||
@@ -145,18 +161,35 @@ class _FinePaymentScreenContent extends StatelessWidget {
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: isNetwork
|
||||
? Image.network(
|
||||
photo,
|
||||
width: 110,
|
||||
height: 110,
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
: Image.asset(
|
||||
photo,
|
||||
child: Image.network(
|
||||
imageUrl,
|
||||
width: 110,
|
||||
height: 110,
|
||||
fit: BoxFit.cover,
|
||||
loadingBuilder: (context, child, loadingProgress) {
|
||||
if (loadingProgress == null) return child;
|
||||
return SizedBox(
|
||||
width: 110,
|
||||
height: 110,
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 28,
|
||||
height: 28,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
value: loadingProgress.expectedTotalBytes != null
|
||||
? loadingProgress.cumulativeBytesLoaded /
|
||||
loadingProgress.expectedTotalBytes!
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const Icon(Icons.error, color: Colors.white, size: 48);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -166,17 +199,17 @@ class _FinePaymentScreenContent extends StatelessWidget {
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
_buildInfoLabel('Самокат:'),
|
||||
_buildInfoLabel('Номер заказа:'),
|
||||
_buildValueRow(
|
||||
'qr_icon.png',
|
||||
fine.scooterNumber,
|
||||
'${fine.orderId}',
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
_buildInfoLabel('Дата:'),
|
||||
_buildInfoLabel('Дата и время:'),
|
||||
Text(
|
||||
fine.date,
|
||||
_formatDateTime(fine.createdAtDateTime),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
@@ -244,111 +277,112 @@ class _FinePaymentScreenContent extends StatelessWidget {
|
||||
|
||||
const SizedBox(height: 28),
|
||||
|
||||
(state.useBalance || state.selectedCard != null)
|
||||
? PaymentOption(
|
||||
title: state.useBalance ? 'Баланс' : "",
|
||||
subtitle: state.useBalance
|
||||
? '${state.userBalance.toStringAsFixed(2)} BYN'
|
||||
: '${state.selectedCard!.cardLastNumber}',
|
||||
isSelected: true,
|
||||
onTap: () async {
|
||||
final result = await showModalBottomSheet<dynamic>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (innerContext) => BlocProvider(
|
||||
create: (context) => PaymentMethodSheetBloc(
|
||||
getIt<GetPaymentCardsUsecase>(),
|
||||
getIt<SetMainPaymentCardUsecase>(),
|
||||
getIt<GetProfileUseCase>(),
|
||||
getIt<AddPaymentCardUsecase>(),
|
||||
)..add(PaymentMethodSheetStarted()),
|
||||
child: PaymentMethodSheet(
|
||||
initialSelectedCard: state.useBalance ? null : state.selectedCard,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (result != null && context.mounted) {
|
||||
if (result is PaymentCard) {
|
||||
context.read<FinePaymentBloc>().add(FinePaymentCardChanged(result));
|
||||
} else if (result == 'balance') {
|
||||
context.read<FinePaymentBloc>().add(SelectFineBalancePressed());
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
: Container(
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
border: Border.all(
|
||||
color: Colors.white.withOpacity(0.4),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
final result = await showModalBottomSheet<dynamic>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (innerContext) => BlocProvider(
|
||||
create: (context) => PaymentMethodSheetBloc(
|
||||
getIt<GetPaymentCardsUsecase>(),
|
||||
getIt<SetMainPaymentCardUsecase>(),
|
||||
getIt<GetProfileUseCase>(),
|
||||
getIt<AddPaymentCardUsecase>(),
|
||||
)..add(PaymentMethodSheetStarted()),
|
||||
child: const PaymentMethodSheet(),
|
||||
if (!isPaid)
|
||||
(state.useBalance || state.selectedCard != null)
|
||||
? PaymentOption(
|
||||
title: state.useBalance ? 'Баланс' : "",
|
||||
subtitle: state.useBalance
|
||||
? '${state.userBalance.toStringAsFixed(2)} BYN'
|
||||
: '${state.selectedCard!.cardLastNumber}',
|
||||
isSelected: true,
|
||||
onTap: () async {
|
||||
final result = await showModalBottomSheet<dynamic>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (innerContext) => BlocProvider(
|
||||
create: (context) => PaymentMethodSheetBloc(
|
||||
getIt<GetPaymentCardsUsecase>(),
|
||||
getIt<SetMainPaymentCardUsecase>(),
|
||||
getIt<GetProfileUseCase>(),
|
||||
getIt<AddPaymentCardUsecase>(),
|
||||
)..add(PaymentMethodSheetStarted()),
|
||||
child: PaymentMethodSheet(
|
||||
initialSelectedCard: state.useBalance ? null : state.selectedCard,
|
||||
),
|
||||
);
|
||||
),
|
||||
);
|
||||
|
||||
if (result != null && context.mounted) {
|
||||
if (result is PaymentCard) {
|
||||
context.read<FinePaymentBloc>().add(FinePaymentCardChanged(result));
|
||||
} else if (result == 'balance') {
|
||||
context.read<FinePaymentBloc>().add(SelectFineBalancePressed());
|
||||
}
|
||||
if (result != null && context.mounted) {
|
||||
if (result is PaymentCard) {
|
||||
context.read<FinePaymentBloc>().add(FinePaymentCardChanged(result));
|
||||
} else if (result == 'balance') {
|
||||
context.read<FinePaymentBloc>().add(SelectFineBalancePressed());
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
: Container(
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
'Способ оплаты',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
border: Border.all(
|
||||
color: Colors.white.withOpacity(0.4),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
final result = await showModalBottomSheet<dynamic>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (innerContext) => BlocProvider(
|
||||
create: (context) => PaymentMethodSheetBloc(
|
||||
getIt<GetPaymentCardsUsecase>(),
|
||||
getIt<SetMainPaymentCardUsecase>(),
|
||||
getIt<GetProfileUseCase>(),
|
||||
getIt<AddPaymentCardUsecase>(),
|
||||
)..add(PaymentMethodSheetStarted()),
|
||||
child: const PaymentMethodSheet(),
|
||||
),
|
||||
);
|
||||
|
||||
if (result != null && context.mounted) {
|
||||
if (result is PaymentCard) {
|
||||
context.read<FinePaymentBloc>().add(FinePaymentCardChanged(result));
|
||||
} else if (result == 'balance') {
|
||||
context.read<FinePaymentBloc>().add(SelectFineBalancePressed());
|
||||
}
|
||||
}
|
||||
},
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
'Способ оплаты',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 12,
|
||||
color: Colors.white.withOpacity(0.6),
|
||||
),
|
||||
Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 12,
|
||||
color: Colors.white.withOpacity(0.4),
|
||||
),
|
||||
Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 12,
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
),
|
||||
],
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 12,
|
||||
color: Colors.white.withOpacity(0.6),
|
||||
),
|
||||
Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 12,
|
||||
color: Colors.white.withOpacity(0.4),
|
||||
),
|
||||
Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 12,
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
);
|
||||
@@ -361,6 +395,11 @@ class _FinePaymentScreenContent extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: BlocBuilder<FinePaymentBloc, FinePaymentState>(
|
||||
builder: (context, state) {
|
||||
final fine = state.fine;
|
||||
if (fine == null || fine.isPaid) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final isButtonDisabled = state.status == FinePaymentStatus.loading ||
|
||||
(!state.useBalance && state.selectedCard == null);
|
||||
|
||||
@@ -418,4 +457,32 @@ class _FinePaymentScreenContent extends StatelessWidget {
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime dateTime) {
|
||||
final now = DateTime.now();
|
||||
final localDate = dateTime.toLocal();
|
||||
|
||||
final isToday = localDate.year == now.year &&
|
||||
localDate.month == now.month &&
|
||||
localDate.day == now.day;
|
||||
|
||||
final yesterday = now.subtract(const Duration(days: 1));
|
||||
final isYesterday = localDate.year == yesterday.year &&
|
||||
localDate.month == yesterday.month &&
|
||||
localDate.day == yesterday.day;
|
||||
|
||||
final time = '${localDate.hour.toString().padLeft(2, '0')}:${localDate.minute.toString().padLeft(2, '0')}';
|
||||
|
||||
if (isToday) {
|
||||
return 'Сегодня, $time';
|
||||
} else if (isYesterday) {
|
||||
return 'Вчера, $time';
|
||||
} else {
|
||||
const months = [
|
||||
'января', 'февраля', 'марта', 'апреля', 'мая', 'июня',
|
||||
'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'
|
||||
];
|
||||
return '${localDate.day} ${months[localDate.month - 1]}, $time';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user