import 'package:comwell_key_app/common/const.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:comwell_key_app/up_sales/components/comwell_radio_button.dart';
import 'package:comwell_key_app/up_sales/components/tags.dart';
import 'package:comwell_key_app/up_sales/components/upsale_header_media.dart';
import 'package:comwell_key_app/up_sales/models/addon_upgrade.dart';
import 'package:comwell_key_app/utils/l10n_utils.dart';
import 'package:flutter/material.dart';
class UpSalesServicesWidget extends StatelessWidget {
final double width;
final double height;
final AddOnUpgrade upgrade;
final bool isSelected;
final bool? isPopular;
final VoidCallback onTap;
final bool showRadioButton;
final bool hasImage;
const UpSalesServicesWidget({
super.key,
this.width = kUpSalesServiceWidgetWidthLarge,
this.height = kUpSalesServiceWidgetHeightLarge,
required this.upgrade,
required this.isSelected,
required this.onTap,
this.isPopular,
this.showRadioButton = true,
this.hasImage = true,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return AnimatedContainer(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
width: width,
height: height,
margin: const EdgeInsets.only(left: 16, right: 8, top: 8, bottom: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: isSelected == true ? sandColor : colorDivider,
width: 1,
),
),
child: hasImage ? _buildWithImage(context, theme) : _buildWithoutImage(context, theme),
);
}
Widget _buildWithImage(BuildContext context, ThemeData theme) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Stack(
children: [
UpsaleHeaderMedia(animationJson: upgrade.animationJson, backgroundImageUrl: upgrade.backgroundImageUrl, images: upgrade.images.toList(), shouldHavePadding: false),
if (isPopular == true)
Positioned(
top: 12,
left: 12,
child: TagWidget(text: context.strings.up_sales_popular.toUpperCase()),
),
],
),
Padding(
padding: const EdgeInsets.only(left: 8, right: 8, top: 16, bottom: 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Text(
upgrade.name,
style: theme.textTheme.headlineMedium,
maxLines: 1,
overflow: TextOverflow.visible,
),
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
context.strings.total_charge_value(upgrade.price.toString()),
style: theme.textTheme.headlineMedium,
),
const SizedBox(width: 8),
if (showRadioButton)
ComwellRadioButton(
selected: isSelected,
onTap: onTap,
),
],
),
],
),
const SizedBox(height: 8),
Text(
upgrade.description,
style: theme.textTheme.bodySmall?.copyWith(
color: colorHeadlineText,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
),
],
),
),
],
);
}
Widget _buildWithoutImage(BuildContext context, ThemeData theme) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(upgrade.name, style: theme.textTheme.headlineMedium),
],
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Row(
children: [
Text(
context.strings.total_charge_value(upgrade.price.toString()),
style: theme.textTheme.headlineMedium,
),
const SizedBox(width: 8),
if (showRadioButton) ComwellRadioButton(selected: isSelected, onTap: onTap),
],
),
],
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (isPopular == true) TagWidget(text: context.strings.up_sales_popular.toUpperCase()),
const SizedBox(height: 8),
SizedBox(
width: 250,
child: Text(
upgrade.description,
style: theme.textTheme.bodySmall?.copyWith(
color: colorHeadlineText,
),
maxLines: 2,
),
),
],
),
],
);
}
}