This commit is contained in:
2026-07-13 01:38:13 +03:00
parent 9eda119527
commit 98c5a7a1d1
54 changed files with 860 additions and 454 deletions

View File

@@ -1,84 +1,108 @@
import 'package:be_happy/presentation/viewmodel/payment_methods_bloc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:path/path.dart';
import '../../core/app_colors.dart';
import '../../di/service_locator.dart';
import '../../domain/entities/payment_card.dart';
import '../../domain/usecase/get_payment_cards_usecase.dart';
import '../../domain/usecase/get_profile_usecase.dart';
import '../../domain/usecase/set_main_payment_card_usecase.dart';
import '../components/app_checkbox.dart';
import '../components/custom_app_bar.dart'; // ✅ Уже есть
import '../components/custom_app_bar.dart';
import '../components/gradient_button.dart';
import '../components/payment_option.dart';
import '../components/sheet/payment_method_sheet.dart';
import '../event/payment_method_sheet_event.dart';
import '../event/payment_methods_event.dart';
import '../event/top_up_event.dart';
import '../state/top_up_state.dart';
import '../viewmodel/payment_method_sheet_bloc.dart';
import '../viewmodel/top_up_bloc.dart';
class TopUpScreen extends StatelessWidget {
const TopUpScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: const BoxDecoration(gradient: AppColors.phoneScreenBg),
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
decoration: const BoxDecoration(gradient: AppColors.phoneScreenBg),
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: BlocListener<TopUpBloc, TopUpState>(
listener: (context, state) {
if (state is TopUpPaymentSuccess) {
context.go('/home/payment-methods/top-up/result/success');
} else if (state is TopUpPaymentFailure) {
context.go('/home/payment-methods/top-up/result/failed');
}
},
child: Column(
children: [
const SizedBox(height: 16),
const CustomAppBar(title: 'Пополнение баланса'),
const SizedBox(height: 20),
BlocBuilder<TopUpBloc, TopUpState>(
builder: (context, state) {
if (state.isLoading) {
return const Center(child: CircularProgressIndicator());
if (state is TopUpLoading) {
return const Expanded(
child: Center(child: CircularProgressIndicator()),
);
}
return Expanded(
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildTariffList(state, context),
const SizedBox(height: 30),
_buildPriceInfo(state),
const SizedBox(height: 40),
const Text(
'Способ оплаты',
style: TextStyle(color: Colors.white70),
),
const SizedBox(height: 15),
_buildCardSelector(state, context),
const SizedBox(height: 20),
_buildAgreement(state, context),
const Spacer(),
_buildPayButton(state, () {
context.read<TopUpBloc>().add(TopUpButtonPressed());
}),
const SizedBox(height: 30),
],
),
],
),
);
if (state is TopUpLoaded) {
if (state.isProcessingPayment) {
return const Expanded(
child: Center(child: CircularProgressIndicator()),
);
}
return Expanded(
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildTariffList(state, context),
const SizedBox(height: 30),
_buildPriceInfo(state),
const SizedBox(height: 40),
const Text(
'Способ оплаты',
style: TextStyle(color: Colors.white70),
),
const SizedBox(height: 15),
_buildCardSelector(state, context),
const SizedBox(height: 20),
_buildAgreement(state, context),
const Spacer(),
_buildPayButton(state, () {
context.read<TopUpBloc>().add(TopUpButtonPressed());
}),
const SizedBox(height: 30),
],
),
],
),
);
}
return const SizedBox.shrink();
},
),
],
),
),
)
),
),
),
);
}
Widget _buildTariffList(TopUpState state, BuildContext context) {
Widget _buildTariffList(TopUpLoaded state, BuildContext context) {
return SizedBox(
height: 120,
child: ListView.separated(
@@ -89,14 +113,11 @@ class TopUpScreen extends StatelessWidget {
final tariff = state.certificates[index];
final isSelected = state.selectedTariff == tariff;
return GestureDetector(
onTap: () =>
context.read<TopUpBloc>().add(SelectCertificate(tariff)),
onTap: () => context.read<TopUpBloc>().add(SelectCertificate(tariff)),
child: Container(
width: 140,
decoration: BoxDecoration(
color: isSelected
? const Color(0xFF80FFC1)
: Colors.white.withOpacity(0.1),
color: isSelected ? const Color(0xFF80FFC1) : Colors.white.withOpacity(0.1),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: Colors.white24),
),
@@ -127,7 +148,7 @@ class TopUpScreen extends StatelessWidget {
);
}
Widget _buildPriceInfo(TopUpState state) {
Widget _buildPriceInfo(TopUpLoaded state) {
if (state.selectedTariff == null) return const SizedBox.shrink();
return Center(
child: Column(
@@ -157,7 +178,7 @@ class TopUpScreen extends StatelessWidget {
);
}
Widget _buildCardSelector(TopUpState state, BuildContext context) {
Widget _buildCardSelector(TopUpLoaded state, BuildContext context) {
return state.selectedCard != null
? Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
@@ -170,16 +191,14 @@ class TopUpScreen extends StatelessWidget {
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (innerContext) =>
BlocProvider(
create: (context) =>
PaymentMethodSheetBloc(
getIt<GetPaymentCardsUsecase>(),
getIt<SetMainPaymentCardUsecase>(),
)
..add(PaymentMethodSheetStarted()),
child: const PaymentMethodSheet(showBalance: false,),
),
builder: (innerContext) => BlocProvider(
create: (context) => PaymentMethodSheetBloc(
getIt<GetPaymentCardsUsecase>(),
getIt<SetMainPaymentCardUsecase>(),
getIt<GetProfileUseCase>(),
)..add(PaymentMethodSheetStarted()),
child: const PaymentMethodSheet(showBalance: false),
),
);
if (selectedCard != null) {
@@ -210,7 +229,6 @@ class TopUpScreen extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Способ оплаты',
style: TextStyle(
@@ -220,21 +238,9 @@ class TopUpScreen extends StatelessWidget {
),
),
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),
),
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)),
],
),
),
@@ -244,20 +250,19 @@ class TopUpScreen extends StatelessWidget {
);
}
Widget _buildAgreement(TopUpState state, BuildContext context) {
Widget _buildAgreement(TopUpLoaded state, BuildContext context) {
return Row(
children: [
AppCheckbox(
value: state.isAgreed,
onChanged: (v) =>
context.read<TopUpBloc>().add(ToggleAgreement(v ?? false)),
onChanged: (v) => context.read<TopUpBloc>().add(ToggleAgreement(v ?? false)),
),
const SizedBox(width: 12),
Flexible(
const Flexible(
child: Text.rich(
TextSpan(
text: 'Я принимаю условия покупки бонусного пакета, при котором денежные средства не подлежат возврату... ',
style: const TextStyle(
text: 'Я принимаю условия покупки бонусного пакека, при котором денежные средства не подлежат возврату... ',
style: TextStyle(
color: AppColors.white70,
fontSize: 12,
),
@@ -268,7 +273,7 @@ class TopUpScreen extends StatelessWidget {
);
}
Widget _buildPayButton(TopUpState state, VoidCallback onTap) {
Widget _buildPayButton(TopUpLoaded state, VoidCallback onTap) {
return GradientButton(
text: 'Оплатить',
onTap: state.isAgreed ? onTap : null,
@@ -279,5 +284,4 @@ class TopUpScreen extends StatelessWidget {
fontSize: 16,
);
}
}