forked from eatvio/eatvio_app
236 lines
12 KiB
Dart
236 lines
12 KiB
Dart
import 'package:eatvio_app/core/app_router.dart';
|
|
import 'package:eatvio_app/core/enums/base_state.dart';
|
|
import 'package:eatvio_app/core/locator_service.dart';
|
|
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
|
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
|
import 'package:eatvio_app/core/widgets/bottom_sheet_handler_bar.dart';
|
|
import 'package:eatvio_app/core/widgets/bottom_sheet_with_blur.dart';
|
|
import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
|
|
import 'package:eatvio_app/core/widgets/data_error_widget.dart';
|
|
import 'package:eatvio_app/core/widgets/loader.dart';
|
|
import 'package:eatvio_app/features/my_finance/presentation/cubit/user_cards_cubit/user_cards_cubit.dart';
|
|
import 'package:eatvio_app/features/my_finance/presentation/cubit/user_cards_cubit/user_cards_state.dart';
|
|
import 'package:eatvio_app/features/my_finance/presentation/widgets/card_widget.dart';
|
|
import 'package:eatvio_app/generated/l10n.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:collection/collection.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
class CardSettingsScreen extends StatelessWidget {
|
|
static const path = '/card-settings-screen';
|
|
static const name = 'cardSettingsScreen';
|
|
const CardSettingsScreen({super.key, this.chosenPlanId});
|
|
final int? chosenPlanId;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocProvider(
|
|
create: (context) => sl<UserCardsCubit>()..getCards(),
|
|
child: CardsSettingsContent(
|
|
chosenPlanId: chosenPlanId,
|
|
));
|
|
}
|
|
}
|
|
|
|
class CardsSettingsContent extends StatelessWidget {
|
|
const CardsSettingsContent({super.key, this.chosenPlanId});
|
|
final int? chosenPlanId;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final s = S.of(context);
|
|
return BlocBuilder<UserCardsCubit, UserCardsState>(
|
|
builder: (context, state) {
|
|
return Scaffold(
|
|
backgroundColor: const Color(0xFFF0F2F5),
|
|
appBar: AppBar(
|
|
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(bottom: Radius.circular(12))),
|
|
title: Text(s.my_cards),
|
|
centerTitle: true,
|
|
),
|
|
body: Column(
|
|
children: [
|
|
const SizedBox(height: 16),
|
|
Container(
|
|
decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), color: Colors.white),
|
|
width: double.infinity,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const SizedBox(height: 16),
|
|
const Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16),
|
|
child: Text('Привязанные карты', style: TextStyle(color: Color(0xFF323F4B), fontSize: 18, fontWeight: FontWeight.w600, height: 1)),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Builder(
|
|
builder: (context) {
|
|
final defaultCardNumber = state.cards.firstWhereOrNull((element) => element.isDefault)?.cardNumber;
|
|
if (defaultCardNumber != null) {
|
|
return Text(
|
|
'Выплату будут производиться\nна карту ${defaultCardNumber.substring(defaultCardNumber.length - 7)}',
|
|
style: const TextStyle(color: Color(0xFF323F4B), fontSize: 16, fontWeight: FontWeight.w500, height: 1),
|
|
);
|
|
}
|
|
return Text(s.no_default_cards, style: TextStyles.textMMedium.copyWith(color: appTheme.black));
|
|
},
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: Builder(
|
|
builder: (context) {
|
|
switch (state.state) {
|
|
case BaseState.error:
|
|
return SizedBox(
|
|
width: MediaQuery.sizeOf(context).width,
|
|
child: Center(
|
|
child: DataErrorWidget(
|
|
onReload: () async {
|
|
context.read<UserCardsCubit>().getCards();
|
|
},
|
|
),
|
|
),
|
|
);
|
|
case BaseState.success:
|
|
return Padding(
|
|
padding: const EdgeInsets.only(left: 12),
|
|
child: Row(
|
|
spacing: 12,
|
|
children: List.generate(state.cards.length + 1, (index) {
|
|
if (index < state.cards.length) {
|
|
final cardsNumber = state.cards[index].cardNumber.substring(state.cards[index].cardNumber.length - 7);
|
|
return CardWidget(isSelected: state.cards[index].isDefault, cardId: state.cards[index].id, cardNumber: cardsNumber);
|
|
}
|
|
return const CardWidget(enabledAddCard: true);
|
|
}),
|
|
),
|
|
);
|
|
|
|
default:
|
|
return SizedBox(width: MediaQuery.sizeOf(context).width, height: 200, child: const Center(child: Loader()));
|
|
}
|
|
},
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
],
|
|
),
|
|
),
|
|
if (chosenPlanId != null && state.cards.isNotEmpty) ...[
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: CustomOutlinedButton(
|
|
text: s.collectCharge,
|
|
height: 52,
|
|
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
|
buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.green)),
|
|
onPressed: () async {
|
|
final defaultCardNumber = state.cards.firstWhereOrNull((element) => element.isDefault)?.cardNumber;
|
|
final result = await context.read<UserCardsCubit>().collectCharge(chosenPlaId: chosenPlanId!);
|
|
if (context.mounted) {
|
|
if (!result) {
|
|
showBottomSheetWithBlur(
|
|
context: context,
|
|
child: Column(
|
|
children: [
|
|
const SizedBox(
|
|
height: 8,
|
|
),
|
|
const BottomSheetHandlerBar(),
|
|
const SizedBox(
|
|
height: 20,
|
|
),
|
|
Text(
|
|
s.chargeCollectionFailed,
|
|
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
|
|
),
|
|
const SizedBox(
|
|
height: 8,
|
|
),
|
|
Text(
|
|
s.contactSupport,
|
|
style: TextStyles.textMMediumAuto.copyWith(color: appTheme.black),
|
|
),
|
|
const SizedBox(
|
|
height: 20,
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
child: CustomOutlinedButton(
|
|
onPressed: () {
|
|
AppRouter.navigatorKey.currentContext?.pop();
|
|
},
|
|
text: s.ok,
|
|
height: 52,
|
|
buttonTextStyle: TextStyles.textSSemibold.copyWith(color: appTheme.whiteA700),
|
|
buttonStyle: ButtonStyle(
|
|
side: const WidgetStatePropertyAll(BorderSide.none),
|
|
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
showBottomSheetWithBlur(
|
|
context: context,
|
|
child: Column(
|
|
children: [
|
|
const SizedBox(
|
|
height: 8,
|
|
),
|
|
const BottomSheetHandlerBar(),
|
|
const SizedBox(
|
|
height: 20,
|
|
),
|
|
Text(
|
|
s.chargeApproved,
|
|
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
|
|
),
|
|
const SizedBox(
|
|
height: 8,
|
|
),
|
|
Text(
|
|
'${s.moneySentToCard} ${defaultCardNumber?.substring(defaultCardNumber.length - 7)}',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyles.textMMediumAuto.copyWith(color: appTheme.black),
|
|
),
|
|
const SizedBox(
|
|
height: 8,
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
child: CustomOutlinedButton(
|
|
onPressed: () {
|
|
AppRouter.navigatorKey.currentContext?.pop();
|
|
},
|
|
text: s.ok,
|
|
height: 52,
|
|
buttonTextStyle: TextStyles.textSSemibold.copyWith(color: appTheme.whiteA700),
|
|
buttonStyle: ButtonStyle(
|
|
side: const WidgetStatePropertyAll(BorderSide.none),
|
|
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
)
|
|
]
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|