Registration pipeline chenged - fill profile step added. Order payment fixed
This commit is contained in:
@@ -30,6 +30,7 @@ class ScooterOrder {
|
|||||||
final double mileage;
|
final double mileage;
|
||||||
final double avgSpeed;
|
final double avgSpeed;
|
||||||
final String payTotalPricePrint;
|
final String payTotalPricePrint;
|
||||||
|
final double unpayTotalPrice;
|
||||||
final String unpayTotalPricePrint;
|
final String unpayTotalPricePrint;
|
||||||
final String totalOrderPricePrint;
|
final String totalOrderPricePrint;
|
||||||
final bool hasFine;
|
final bool hasFine;
|
||||||
@@ -65,6 +66,7 @@ class ScooterOrder {
|
|||||||
required this.avgSpeed,
|
required this.avgSpeed,
|
||||||
required this.payTotalPricePrint, // оплачено
|
required this.payTotalPricePrint, // оплачено
|
||||||
required this.unpayTotalPricePrint, //неоплачено
|
required this.unpayTotalPricePrint, //неоплачено
|
||||||
|
required this.unpayTotalPrice, //неоплачено
|
||||||
required this.totalOrderPricePrint, //общая
|
required this.totalOrderPricePrint, //общая
|
||||||
required this.hasFine,
|
required this.hasFine,
|
||||||
});
|
});
|
||||||
@@ -115,6 +117,7 @@ class ScooterOrder {
|
|||||||
avgSpeed: (json['avgSpeed'] as num?)?.toDouble() ?? 0.0,
|
avgSpeed: (json['avgSpeed'] as num?)?.toDouble() ?? 0.0,
|
||||||
payTotalPricePrint: paymentInfo?['payTotalPricePrint'] ?? '',
|
payTotalPricePrint: paymentInfo?['payTotalPricePrint'] ?? '',
|
||||||
unpayTotalPricePrint: paymentInfo?['unpayTotalPricePrint'] ?? '',
|
unpayTotalPricePrint: paymentInfo?['unpayTotalPricePrint'] ?? '',
|
||||||
|
unpayTotalPrice: (paymentInfo?['unpayTotalPrice'] as num?)?.toDouble() ?? 0.0,
|
||||||
totalOrderPricePrint: paymentInfo?['totalOrderPricePrint'] ?? '',
|
totalOrderPricePrint: paymentInfo?['totalOrderPricePrint'] ?? '',
|
||||||
hasFine: paymentInfo?['hasFine'] ?? false,
|
hasFine: paymentInfo?['hasFine'] ?? false,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
class CustomAppBar extends StatelessWidget {
|
class CustomAppBar extends StatelessWidget {
|
||||||
final String title;
|
final String title;
|
||||||
|
final showBackButton;
|
||||||
|
|
||||||
const CustomAppBar({super.key, required this.title});
|
const CustomAppBar({super.key, required this.title, this.showBackButton = true});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
|
if (showBackButton)
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () => Navigator.pop(context),
|
onTap: () => Navigator.pop(context),
|
||||||
child: Row(
|
child: Row(
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -9,15 +9,22 @@ import '../../domain/entities/user_profile.dart';
|
|||||||
import '../components/custom_app_bar.dart';
|
import '../components/custom_app_bar.dart';
|
||||||
import '../components/gradient_button.dart';
|
import '../components/gradient_button.dart';
|
||||||
import '../event/edit_profile_event.dart';
|
import '../event/edit_profile_event.dart';
|
||||||
import '../state/edit_profile_state.dart';
|
|
||||||
import '../event/profile_event.dart';
|
import '../event/profile_event.dart';
|
||||||
|
import '../event/spalsh_event.dart';
|
||||||
|
import '../state/edit_profile_state.dart';
|
||||||
import '../viewmodel/edit_profile_bloc.dart';
|
import '../viewmodel/edit_profile_bloc.dart';
|
||||||
import '../viewmodel/profile_bloc.dart';
|
import '../viewmodel/profile_bloc.dart';
|
||||||
|
import '../viewmodel/splash_bloc.dart';
|
||||||
|
|
||||||
class EditProfileScreen extends StatefulWidget {
|
class EditProfileScreen extends StatefulWidget {
|
||||||
final UserProfile profile;
|
final UserProfile profile;
|
||||||
|
final bool isRegistration;
|
||||||
|
|
||||||
const EditProfileScreen({super.key, required this.profile});
|
const EditProfileScreen({
|
||||||
|
super.key,
|
||||||
|
required this.profile,
|
||||||
|
this.isRegistration = false,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<EditProfileScreen> createState() => _EditProfileScreenState();
|
State<EditProfileScreen> createState() => _EditProfileScreenState();
|
||||||
@@ -52,6 +59,36 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
birthDateController = TextEditingController(text: initialDateText);
|
birthDateController = TextEditingController(text: initialDateText);
|
||||||
|
|
||||||
|
nameController.addListener(_onFieldChanged);
|
||||||
|
birthDateController.addListener(_onFieldChanged);
|
||||||
|
phoneController.addListener(_onFieldChanged);
|
||||||
|
emailController.addListener(_onFieldChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onFieldChanged() {
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get _isFormValid {
|
||||||
|
return nameController.text.trim().isNotEmpty &&
|
||||||
|
birthDateController.text.trim().isNotEmpty &&
|
||||||
|
phoneController.text.trim().isNotEmpty &&
|
||||||
|
emailController.text.trim().isNotEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
nameController.removeListener(_onFieldChanged);
|
||||||
|
birthDateController.removeListener(_onFieldChanged);
|
||||||
|
phoneController.removeListener(_onFieldChanged);
|
||||||
|
emailController.removeListener(_onFieldChanged);
|
||||||
|
|
||||||
|
nameController.dispose();
|
||||||
|
birthDateController.dispose();
|
||||||
|
phoneController.dispose();
|
||||||
|
emailController.dispose();
|
||||||
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _submit(BuildContext context) {
|
void _submit(BuildContext context) {
|
||||||
@@ -61,14 +98,13 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
|||||||
final String birthDateForApi = _selectedBirthDate?.toIso8601String() ?? '';
|
final String birthDateForApi = _selectedBirthDate?.toIso8601String() ?? '';
|
||||||
|
|
||||||
final updatedProfile = profileFromState.copyWith(
|
final updatedProfile = profileFromState.copyWith(
|
||||||
name: nameController.text,
|
name: nameController.text.trim(),
|
||||||
birthDate: birthDateForApi.isNotEmpty ? "${birthDateForApi}Z" : '',
|
birthDate: birthDateForApi.isNotEmpty ? "${birthDateForApi}Z" : '',
|
||||||
email: emailController.text,
|
email: emailController.text.trim(),
|
||||||
);
|
);
|
||||||
|
|
||||||
context.read<EditProfileBloc>().add(EditProfileSubmitted(updatedProfile));
|
context.read<EditProfileBloc>().add(EditProfileSubmitted(updatedProfile));
|
||||||
context.read<ProfileBloc>().add(ProfileUpdated());
|
context.read<ProfileBloc>().add(ProfileUpdated());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _selectDate(BuildContext context) async {
|
Future<void> _selectDate(BuildContext context) async {
|
||||||
@@ -90,6 +126,8 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final bool isButtonEnabled = widget.isRegistration ? _isFormValid : true;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Container(
|
body: Container(
|
||||||
decoration: const BoxDecoration(gradient: AppColors.phoneScreenBg),
|
decoration: const BoxDecoration(gradient: AppColors.phoneScreenBg),
|
||||||
@@ -104,15 +142,21 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
|||||||
phoneController.text = profile.phone;
|
phoneController.text = profile.phone;
|
||||||
emailController.text = profile.email;
|
emailController.text = profile.email;
|
||||||
birthDateController.text = profile.birthDate;
|
birthDateController.text = profile.birthDate;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.isSuccess) {
|
if (state.isSuccess) {
|
||||||
getIt<ProfileBloc>().add(ProfileUpdated());
|
getIt<ProfileBloc>().add(ProfileUpdated());
|
||||||
context.pop();
|
if (widget.isRegistration) {
|
||||||
|
context.read<SplashBloc>().add(PinVerificationSuccess());
|
||||||
|
context.go('/home');
|
||||||
|
} else {
|
||||||
|
context.pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (state.error != null) {
|
if (state.error != null) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(state.error!)));
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(state.error!)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
@@ -125,7 +169,10 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
|||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
CustomAppBar(title: 'Личные данные'),
|
CustomAppBar(
|
||||||
|
title: widget.isRegistration ? 'Заполните профиль' : 'Личные данные',
|
||||||
|
showBackButton: !widget.isRegistration,
|
||||||
|
),
|
||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
_Field(
|
_Field(
|
||||||
'Имя',
|
'Имя',
|
||||||
@@ -137,9 +184,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
|||||||
birthDateController,
|
birthDateController,
|
||||||
iconPath: 'assets/icons/edit.png',
|
iconPath: 'assets/icons/edit.png',
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
onTap: () => _selectDate(
|
onTap: () => _selectDate(context),
|
||||||
context,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
_Field(
|
_Field(
|
||||||
'Телефон',
|
'Телефон',
|
||||||
@@ -156,13 +201,13 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
|||||||
state.isSaving
|
state.isSaving
|
||||||
? const CircularProgressIndicator(color: Colors.white)
|
? const CircularProgressIndicator(color: Colors.white)
|
||||||
: GradientButton(
|
: GradientButton(
|
||||||
text: 'Сохранить изменения',
|
text: widget.isRegistration ? 'Продолжить' : 'Сохранить изменения',
|
||||||
onTap: () => _submit(context),
|
onTap: isButtonEnabled ? () => _submit(context) : null,
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: 56,
|
height: 56,
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
showArrows: true,
|
showArrows: true,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -173,7 +218,6 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class _Field extends StatelessWidget {
|
class _Field extends StatelessWidget {
|
||||||
|
|||||||
@@ -115,6 +115,8 @@ class _PaymentConfirmScreenContent extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final hasNoDebt = (order?.unpayTotalPrice ?? 0) == 0;
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@@ -141,7 +143,7 @@ class _PaymentConfirmScreenContent extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment:
|
crossAxisAlignment:
|
||||||
CrossAxisAlignment.start,
|
CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
_buildInfoLabel('Стоимость поездки:'),
|
_buildInfoLabel('Стоимость поездки:'),
|
||||||
_buildValueRow(
|
_buildValueRow(
|
||||||
@@ -154,7 +156,7 @@ class _PaymentConfirmScreenContent extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment:
|
crossAxisAlignment:
|
||||||
CrossAxisAlignment.start,
|
CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
_buildInfoLabel('Оплачено:'),
|
_buildInfoLabel('Оплачено:'),
|
||||||
_buildValueRow(
|
_buildValueRow(
|
||||||
@@ -183,7 +185,7 @@ class _PaymentConfirmScreenContent extends StatelessWidget {
|
|||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment:
|
mainAxisAlignment:
|
||||||
MainAxisAlignment.center,
|
MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Image.asset(
|
Image.asset(
|
||||||
'assets/icons/money_icon.png',
|
'assets/icons/money_icon.png',
|
||||||
@@ -204,114 +206,115 @@ class _PaymentConfirmScreenContent extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
const SizedBox(height: 40),
|
// 🔹 КАРТА ОПЛАТЫ (Отображается только если есть долг)
|
||||||
|
if (!hasNoDebt) ...[
|
||||||
// 🔹 КАРТА ОПЛАТЫ
|
const SizedBox(height: 40),
|
||||||
(state.useBalance || state.selectedCard != null)
|
(state.useBalance || state.selectedCard != null)
|
||||||
? Padding(padding: const EdgeInsets.symmetric(horizontal: 20),
|
? Padding(
|
||||||
child: PaymentOption(
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||||
title: state.useBalance ? 'Баланс' : "",
|
child: PaymentOption(
|
||||||
subtitle: state.useBalance
|
title: state.useBalance ? 'Баланс' : "",
|
||||||
? '${state.userBalance.toStringAsFixed(2)} BYN'
|
subtitle: state.useBalance
|
||||||
: '${state.selectedCard!.cardLastNumber}',
|
? '${state.userBalance.toStringAsFixed(2)} BYN'
|
||||||
isSelected: true,
|
: '${state.selectedCard!.cardLastNumber}',
|
||||||
onTap: () async {
|
isSelected: true,
|
||||||
final result = await showModalBottomSheet<dynamic>(
|
onTap: () async {
|
||||||
context: context,
|
final result = await showModalBottomSheet<dynamic>(
|
||||||
isScrollControlled: true,
|
context: context,
|
||||||
backgroundColor: Colors.transparent,
|
isScrollControlled: true,
|
||||||
builder: (innerContext) => BlocProvider(
|
backgroundColor: Colors.transparent,
|
||||||
create: (context) => PaymentMethodSheetBloc(
|
builder: (innerContext) => BlocProvider(
|
||||||
getIt<GetPaymentCardsUsecase>(),
|
create: (context) => PaymentMethodSheetBloc(
|
||||||
getIt<SetMainPaymentCardUsecase>(),
|
getIt<GetPaymentCardsUsecase>(),
|
||||||
getIt<GetProfileUseCase>(),
|
getIt<SetMainPaymentCardUsecase>(),
|
||||||
getIt<AddPaymentCardUsecase>(),
|
getIt<GetProfileUseCase>(),
|
||||||
)..add(PaymentMethodSheetStarted()),
|
getIt<AddPaymentCardUsecase>(),
|
||||||
child: PaymentMethodSheet(
|
)..add(PaymentMethodSheetStarted()),
|
||||||
initialSelectedCard: state.useBalance ? null : state.selectedCard,
|
child: PaymentMethodSheet(
|
||||||
),
|
initialSelectedCard: state.useBalance ? null : state.selectedCard,
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result != null) {
|
|
||||||
if (result is PaymentCard) {
|
|
||||||
context.read<PaymentConfirmBloc>().add(PaymentCardChanged(result));
|
|
||||||
} else if (result == 'balance') {
|
|
||||||
context.read<PaymentConfirmBloc>().add(SelectBalancePressed());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 20,
|
|
||||||
),
|
|
||||||
child: 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: () {
|
|
||||||
context.pushReplacement(
|
|
||||||
'/home/payment-method-sheet',
|
|
||||||
);
|
|
||||||
|
|
||||||
},
|
if (result != null) {
|
||||||
borderRadius: BorderRadius.circular(
|
if (result is PaymentCard) {
|
||||||
24,
|
context.read<PaymentConfirmBloc>().add(PaymentCardChanged(result));
|
||||||
),
|
} else if (result == 'balance') {
|
||||||
child: Center(
|
context.read<PaymentConfirmBloc>().add(SelectBalancePressed());
|
||||||
child: Row(
|
}
|
||||||
mainAxisAlignment:
|
}
|
||||||
MainAxisAlignment.center,
|
},
|
||||||
children: [
|
),
|
||||||
const Text(
|
)
|
||||||
'Способ оплаты',
|
: Padding(
|
||||||
style: TextStyle(
|
padding: const EdgeInsets.symmetric(
|
||||||
color: Colors.white,
|
horizontal: 20,
|
||||||
fontSize: 16,
|
),
|
||||||
fontWeight:
|
child: Container(
|
||||||
FontWeight.w600,
|
height: 56,
|
||||||
),
|
decoration: BoxDecoration(
|
||||||
),
|
borderRadius: BorderRadius.circular(
|
||||||
const SizedBox(width: 8),
|
24,
|
||||||
Icon(
|
),
|
||||||
Icons.arrow_forward_ios,
|
border: Border.all(
|
||||||
size: 12,
|
color: Colors.white.withOpacity(
|
||||||
color: Colors.white
|
0.4,
|
||||||
.withOpacity(0.6),
|
),
|
||||||
),
|
width: 1,
|
||||||
Icon(
|
),
|
||||||
Icons.arrow_forward_ios,
|
),
|
||||||
size: 12,
|
child: Material(
|
||||||
color: Colors.white
|
color: Colors.transparent,
|
||||||
.withOpacity(0.4),
|
child: InkWell(
|
||||||
),
|
onTap: () {
|
||||||
Icon(
|
context.pushReplacement(
|
||||||
Icons.arrow_forward_ios,
|
'/home/payment-method-sheet',
|
||||||
size: 12,
|
);
|
||||||
color: Colors.white
|
},
|
||||||
.withOpacity(0.2),
|
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),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -322,45 +325,53 @@ class _PaymentConfirmScreenContent extends StatelessWidget {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(24.0),
|
padding: const EdgeInsets.all(24.0),
|
||||||
child:
|
child:
|
||||||
BlocConsumer<PaymentConfirmBloc, PaymentConfirmState>(
|
BlocConsumer<PaymentConfirmBloc, PaymentConfirmState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state.status == PaymentConfirmStatus.success &&
|
if (state.status == PaymentConfirmStatus.success &&
|
||||||
state.paymentCompleted) {
|
state.paymentCompleted) {
|
||||||
|
context.go('/home');
|
||||||
|
} else if (state.status ==
|
||||||
|
PaymentConfirmStatus.failure) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
state.errorMessage ?? 'Ошибка оплаты',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
builder: (context, state) {
|
||||||
|
final hasNoDebt = (state.order?.unpayTotalPrice ?? 0) == 0;
|
||||||
|
|
||||||
|
return GradientButton(
|
||||||
|
text: state.status == PaymentConfirmStatus.loading
|
||||||
|
? 'Обработка...'
|
||||||
|
: (hasNoDebt ? 'Продолжить' : 'Оплатить'),
|
||||||
|
showArrows: true,
|
||||||
|
height: 56,
|
||||||
|
width: double.infinity,
|
||||||
|
onTap: (state.status == PaymentConfirmStatus.loading ||
|
||||||
|
(!hasNoDebt && !state.useBalance && state.selectedCard == null))
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
if (hasNoDebt) {
|
||||||
|
context.read<MapBloc>().add(ClearMapPlacemarks());
|
||||||
context.go('/home');
|
context.go('/home');
|
||||||
} else if (state.status ==
|
} else {
|
||||||
PaymentConfirmStatus.failure) {
|
context.read<PaymentConfirmBloc>().add(
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
PayRide(
|
||||||
SnackBar(
|
cardId: state.useBalance ? null : state.selectedCard?.id,
|
||||||
content: Text(
|
isBalance: state.useBalance,
|
||||||
state.errorMessage ?? 'Ошибка оплаты',
|
orderId: orderId,
|
||||||
),
|
photoIds: photoIds,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
builder: (context, state) {
|
);
|
||||||
return GradientButton(
|
},
|
||||||
text: state.status == PaymentConfirmStatus.loading
|
),
|
||||||
? 'Обработка...'
|
|
||||||
: 'Оплатить',
|
|
||||||
showArrows: true,
|
|
||||||
height: 56,
|
|
||||||
width: double.infinity,
|
|
||||||
onTap: (state.status == PaymentConfirmStatus.loading || (!state.useBalance && state.selectedCard == null))
|
|
||||||
? null
|
|
||||||
: () {
|
|
||||||
context.read<PaymentConfirmBloc>().add(
|
|
||||||
PayRide(
|
|
||||||
cardId: state.useBalance ? null : state.selectedCard?.id,
|
|
||||||
isBalance: state.useBalance,
|
|
||||||
orderId: orderId,
|
|
||||||
photoIds: photoIds,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -371,7 +382,6 @@ class _PaymentConfirmScreenContent extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Вспомогательный метод для подзаголовков
|
|
||||||
Widget _buildInfoLabel(String text) {
|
Widget _buildInfoLabel(String text) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 8),
|
padding: const EdgeInsets.only(bottom: 8),
|
||||||
@@ -382,7 +392,6 @@ class _PaymentConfirmScreenContent extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Вспомогательный метод для строк со значениями и иконками
|
|
||||||
Widget _buildValueRow(String iconName, String value) {
|
Widget _buildValueRow(String iconName, String value) {
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
@@ -405,4 +414,4 @@ class _PaymentConfirmScreenContent extends StatelessWidget {
|
|||||||
final m = minutes % 60;
|
final m = minutes % 60;
|
||||||
return '${h.toString().padLeft(2, '0')}:${m.toString().padLeft(2, '0')}';
|
return '${h.toString().padLeft(2, '0')}:${m.toString().padLeft(2, '0')}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,11 +4,11 @@ import 'package:go_router/go_router.dart';
|
|||||||
import '../../core/app_colors.dart';
|
import '../../core/app_colors.dart';
|
||||||
import '../components/code_dots.dart';
|
import '../components/code_dots.dart';
|
||||||
import '../event/map_event.dart';
|
import '../event/map_event.dart';
|
||||||
|
import '../event/pin_event.dart';
|
||||||
import '../event/spalsh_event.dart';
|
import '../event/spalsh_event.dart';
|
||||||
|
import '../state/pin_state.dart';
|
||||||
import '../viewmodel/map_bloc.dart';
|
import '../viewmodel/map_bloc.dart';
|
||||||
import '../viewmodel/pin_bloc.dart';
|
import '../viewmodel/pin_bloc.dart';
|
||||||
import '../event/pin_event.dart';
|
|
||||||
import '../state/pin_state.dart';
|
|
||||||
import '../viewmodel/splash_bloc.dart';
|
import '../viewmodel/splash_bloc.dart';
|
||||||
|
|
||||||
class PinLoginScreen extends StatefulWidget {
|
class PinLoginScreen extends StatefulWidget {
|
||||||
@@ -52,8 +52,14 @@ class _PinLoginScreenState extends State<PinLoginScreen> {
|
|||||||
return BlocListener<PinBloc, PinState>(
|
return BlocListener<PinBloc, PinState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state is PinSuccess) {
|
if (state is PinSuccess) {
|
||||||
context.read<SplashBloc>().add(PinVerificationSuccess());
|
if (state.isProfileIncomplete) {
|
||||||
context.go("/home");
|
// Переходим на заполнение профиля, если хотя бы одно поле пустое
|
||||||
|
context.go('/edit-profile?isRegistration=true');
|
||||||
|
} else {
|
||||||
|
// Все поля заполнены — завершаем авторизацию и идем на главный экран
|
||||||
|
context.read<SplashBloc>().add(PinVerificationSuccess());
|
||||||
|
context.go('/home');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (state.error != null) {
|
if (state.error != null) {
|
||||||
controller.clear();
|
controller.clear();
|
||||||
@@ -128,7 +134,6 @@ class _PinLoginScreenState extends State<PinLoginScreen> {
|
|||||||
|
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
|
|
||||||
// Блок ошибки
|
|
||||||
if (state.error != null)
|
if (state.error != null)
|
||||||
Text(
|
Text(
|
||||||
state.error!,
|
state.error!,
|
||||||
@@ -157,14 +162,13 @@ class _PinLoginScreenState extends State<PinLoginScreen> {
|
|||||||
"Забыли PIN-код?",
|
"Забыли PIN-код?",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: AppColors.whiteText,
|
color: AppColors.whiteText,
|
||||||
decoration: TextDecoration.underline,
|
decoration: TextDecoration.underline,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
const SizedBox(height: 40),
|
const SizedBox(height: 40),
|
||||||
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -23,5 +23,10 @@ class PinLoading extends PinState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PinSuccess extends PinState {
|
class PinSuccess extends PinState {
|
||||||
const PinSuccess() : super(pin: '');
|
final bool isProfileIncomplete;
|
||||||
|
|
||||||
|
const PinSuccess({this.isProfileIncomplete = false}) : super(pin: '');
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [isProfileIncomplete];
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,24 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:be_happy/domain/usecase/verify_pin_usecase.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import '../../domain/usecase/create_pin_usecase.dart';
|
||||||
|
import '../../domain/usecase/get_profile_usecase.dart';
|
||||||
import '../../domain/usecase/is_pin_set_usecase.dart';
|
import '../../domain/usecase/is_pin_set_usecase.dart';
|
||||||
|
import '../../domain/usecase/verify_pin_usecase.dart';
|
||||||
import '../event/pin_event.dart';
|
import '../event/pin_event.dart';
|
||||||
import '../state/pin_state.dart';
|
import '../state/pin_state.dart';
|
||||||
import '../../domain/usecase/create_pin_usecase.dart';
|
|
||||||
|
|
||||||
class PinBloc extends Bloc<PinEvent, PinState> {
|
class PinBloc extends Bloc<PinEvent, PinState> {
|
||||||
final CreatePinUseCase createPinUseCase;
|
final CreatePinUseCase createPinUseCase;
|
||||||
final VerifyPinUseCase verifyPinUsecase;
|
final VerifyPinUseCase verifyPinUsecase;
|
||||||
final IsPinSetUsecase isPinSetUsecase;
|
final IsPinSetUsecase isPinSetUsecase;
|
||||||
|
final GetProfileUseCase getProfileUseCase;
|
||||||
|
|
||||||
PinBloc({
|
PinBloc({
|
||||||
required this.createPinUseCase,
|
required this.createPinUseCase,
|
||||||
required this.verifyPinUsecase,
|
required this.verifyPinUsecase,
|
||||||
required this.isPinSetUsecase,
|
required this.isPinSetUsecase,
|
||||||
bool isRegistration = true,
|
required this.getProfileUseCase,
|
||||||
}) : super(const PinLoading()) {
|
}) : super(const PinLoading()) {
|
||||||
on<PinDigitChanged>(_onPinChanged);
|
on<PinDigitChanged>(_onPinChanged);
|
||||||
on<PinSubmitted>(_onPinSubmitted);
|
on<PinSubmitted>(_onPinSubmitted);
|
||||||
@@ -46,35 +48,52 @@ class PinBloc extends Bloc<PinEvent, PinState> {
|
|||||||
try {
|
try {
|
||||||
if (isCreateMode) {
|
if (isCreateMode) {
|
||||||
await createPinUseCase(currentPin);
|
await createPinUseCase(currentPin);
|
||||||
emit(const PinSuccess());
|
|
||||||
} else {
|
} else {
|
||||||
final isValid = await verifyPinUsecase(currentPin);
|
final isValid = await verifyPinUsecase(currentPin);
|
||||||
if (isValid) {
|
if (!isValid) {
|
||||||
emit(const PinSuccess());
|
|
||||||
} else {
|
|
||||||
throw Exception("Неверный ПИН-код");
|
throw Exception("Неверный ПИН-код");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Проверяем заполненность профиля
|
||||||
|
bool isProfileIncomplete = true;
|
||||||
|
try {
|
||||||
|
final profile = await getProfileUseCase();
|
||||||
|
|
||||||
|
// Если хотя бы одно из обязательных полей пустое — профиль считается незаполненным
|
||||||
|
isProfileIncomplete = profile.name.trim().isEmpty ||
|
||||||
|
profile.birthDate.trim().isEmpty ||
|
||||||
|
profile.email.trim().isEmpty ||
|
||||||
|
profile.phone.trim().isEmpty;
|
||||||
|
} catch (_) {
|
||||||
|
isProfileIncomplete = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(PinSuccess(isProfileIncomplete: isProfileIncomplete));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isCreateMode) {
|
if (isCreateMode) {
|
||||||
emit(PinCreateInProgress(pin: '', error: e.toString()));
|
emit(PinCreateInProgress(pin: '', error: e.toString()));
|
||||||
} else {
|
} else {
|
||||||
emit(PinLoginInProgress(pin: '', error: e.toString().contains("Неверный")
|
emit(PinLoginInProgress(
|
||||||
? "Неверный ПИН-код"
|
pin: '',
|
||||||
: "Ошибка при проверке"));
|
error: e.toString().contains("Неверный")
|
||||||
|
? "Неверный ПИН-код"
|
||||||
|
: "Ошибка при проверке",
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onPinScreenStarted(PinScreenStarted event, Emitter<PinState> emit) async {
|
FutureOr<void> _onPinScreenStarted(
|
||||||
|
PinScreenStarted event,
|
||||||
|
Emitter<PinState> emit,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
final bool hasPin = await isPinSetUsecase();
|
final bool hasPin = await isPinSetUsecase();
|
||||||
|
|
||||||
if (hasPin) {
|
if (hasPin) {
|
||||||
// Пин ЕСТЬ в базе — значит, нужно его ВВЕСТИ (Login)
|
|
||||||
emit(const PinLoginInProgress(pin: ''));
|
emit(const PinLoginInProgress(pin: ''));
|
||||||
} else {
|
} else {
|
||||||
// Пина НЕТ в базе — значит, нужно его СОЗДАТЬ (Create)
|
|
||||||
emit(const PinCreateInProgress(pin: ''));
|
emit(const PinCreateInProgress(pin: ''));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user