You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_Patient_App_New/lib/widgets/chip/custom_chip_widget.dart

75 lines
2.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/enums.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
class CustomChipWidget extends StatelessWidget {
final ChipTypeEnum chipType;
final String chipText;
final String? iconAsset;
final VoidCallback? onTap;
final bool isSelected;
final double borderRadius;
final EdgeInsetsGeometry padding;
final Color? backgroundColor;
final Color? textColor;
final Color? borderColor;
final bool isShowBorder;
const CustomChipWidget({
super.key,
required this.chipType,
required this.chipText,
this.iconAsset,
this.onTap,
this.isSelected = false,
this.borderRadius = 12,
this.padding = const EdgeInsets.all(8),
this.backgroundColor,
this.textColor,
this.borderColor,
this.isShowBorder = false,
});
@override
Widget build(BuildContext context) {
final hasIcon = iconAsset != null;
final hasOnTap = onTap != null || hasIcon;
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(borderRadius),
color: isSelected ? chipType.color : backgroundColor ?? chipType.backgroundColor,
border: isShowBorder
? Border.all(
color: chipType.color,
width: isSelected ? 0 : 1,
)
: null,
),
child: InkWell(
onTap: hasOnTap ? onTap : null,
borderRadius: BorderRadius.circular(borderRadius),
child: Container(
padding: padding,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(borderRadius),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (iconAsset != null) ...[
Utils.buildSvgWithAssets(icon: iconAsset!),
SizedBox(width: 4.h),
],
chipText.toText10(isBold: true, color: isSelected ? Colors.white : textColor ?? chipType.color, maxlines: 1, weight: FontWeight.w500, letterSpacing: -0.5),
],
),
),
),
);
}
}