forked from eatvio/eatvio_app
card adding and selecting default one
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/my_finance/presentation/cubit/user_cards_cubit/user_cards_cubit.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class CardWidget extends StatelessWidget {
|
||||
const CardWidget({super.key, this.isSelected = false, this.enabledAddCard = false, this.cardId = 0, this.cardNumber = ''});
|
||||
final int cardId;
|
||||
final bool isSelected;
|
||||
final bool enabledAddCard;
|
||||
final String cardNumber;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return GestureDetector(
|
||||
onTap: enabledAddCard
|
||||
? () async {
|
||||
final addCardUrl = await context.read<UserCardsCubit>().addCard();
|
||||
|
||||
if (addCardUrl != null) {
|
||||
final uri = Uri.parse(addCardUrl.paymentUrl);
|
||||
if (await canLaunchUrl(uri)) {
|
||||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
}
|
||||
}
|
||||
}
|
||||
: () {
|
||||
context.read<UserCardsCubit>().markAsDefault(id: cardId);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: isSelected ? appTheme.blueA400 : Color(0xFFF1F2F6), width: 2),
|
||||
),
|
||||
child: enabledAddCard
|
||||
? Container(
|
||||
width: 148,
|
||||
padding: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(color: Color(0xFFF1F2F6), borderRadius: BorderRadius.circular(4)),
|
||||
child: Column(
|
||||
children: [
|
||||
SvgPicture.asset('assets/icons/add_card.svg'),
|
||||
const SizedBox(height: 24),
|
||||
Text(s.new_card, style: TextStyles.textSSemibold.copyWith(color: appTheme.black)),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Container(
|
||||
width: 148,
|
||||
padding: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(color: Color(0xFFF1F2F6), borderRadius: BorderRadius.circular(4)),
|
||||
child: Column(
|
||||
children: [
|
||||
SvgPicture.asset('assets/icons/card.svg'),
|
||||
const SizedBox(height: 24),
|
||||
Text(cardNumber, style: TextStyles.textSSemibold.copyWith(color: appTheme.black)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user