import 'card_details.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; class CardProviderIcon extends StatefulWidget { const CardProviderIcon({required this.cardDetails, super.key}); final CardDetails? cardDetails; @override State createState() => _CardProviderIconState(); } class _CardProviderIconState extends State { final Map cardProviderSvg = { 'credit-card': '', 'error': '', CardProviderID.discoverCard.name: '', CardProviderID.americanExpress.name: '', CardProviderID.mastercard.name: '', CardProviderID.visa.name: '', CardProviderID.dinersClub.name: '', CardProviderID.jcb.name: '', }; final double height = 20; final double width = 30; @override Widget build(BuildContext context) { late Widget child; if (widget.cardDetails?.cardNumber != null && widget.cardDetails!.cardNumberFilled && widget.cardDetails!.validState == ValidState.invalidCard) { child = Padding( padding: const EdgeInsets.symmetric(horizontal: 5.0), child: SvgPicture.string( key: const Key('invalid-card'), cardProviderSvg['error']!, height: height, width: width, ), ); } else { if (widget.cardDetails?.provider?.id == null) { child = Padding( padding: const EdgeInsets.symmetric(horizontal: 5.0), child: SvgPicture.string( key: const Key('credit_card'), cardProviderSvg['credit-card']!, height: height, width: width, ), ); } else { child = createCardSvg(widget.cardDetails!.provider!.id); } } return AnimatedSwitcher( duration: const Duration(milliseconds: 150), transitionBuilder: (child, animation) { return ScaleTransition( scale: animation, child: FadeTransition( opacity: animation, child: child, )); }, child: child, ); } Widget createCardSvg(CardProviderID id) { return SvgPicture.string( key: Key('${id.name}-card'), cardProviderSvg[id.name]!, height: height, width: width, ); } }