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.
67 lines
2.2 KiB
Dart
67 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
|
|
|
|
/// Small pill-shaped badge used for retailer/offer meta info (type, validity, location, usage, ...).
|
|
/// Flexible via optional params - every call only needs to override what differs from the given defaults.
|
|
class InfoChipWidget extends StatelessWidget {
|
|
final String text;
|
|
final Color backgroundColor;
|
|
final Color textColor;
|
|
final Color? iconColor;
|
|
final IconData? icon;
|
|
final String? svgIcon;
|
|
final bool isBold;
|
|
final double iconSize;
|
|
final double iconTextGap;
|
|
final double horizontalPadding;
|
|
final double verticalPadding;
|
|
final double borderRadius;
|
|
final Color? borderColor;
|
|
final double borderWidth;
|
|
|
|
const InfoChipWidget({
|
|
Key? key,
|
|
required this.text,
|
|
required this.backgroundColor,
|
|
required this.textColor,
|
|
this.iconColor,
|
|
this.icon,
|
|
this.svgIcon,
|
|
this.isBold = true,
|
|
this.iconSize = 10,
|
|
this.iconTextGap = 3,
|
|
this.horizontalPadding = 7,
|
|
this.verticalPadding = 2.5,
|
|
this.borderRadius = 10,
|
|
this.borderColor,
|
|
this.borderWidth = 1,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: EdgeInsets.symmetric(horizontal: horizontalPadding, vertical: verticalPadding),
|
|
decoration: BoxDecoration(
|
|
color: backgroundColor,
|
|
borderRadius: BorderRadius.circular(borderRadius),
|
|
border: Border.all(color: (borderColor ?? textColor).withValues(alpha: 0.7), width: borderWidth),
|
|
),
|
|
child:
|
|
(icon == null && svgIcon == null)
|
|
? text.toText10(isBold: isBold, color: textColor)
|
|
: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: <Widget>[_buildIcon(), SizedBox(width: iconTextGap), text.toText10(isBold: isBold, color: textColor)],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildIcon() {
|
|
if (svgIcon != null) {
|
|
return SvgPicture.asset(svgIcon!, width: iconSize, height: iconSize, colorFilter: ColorFilter.mode(iconColor ?? textColor, BlendMode.srcIn));
|
|
}
|
|
return Icon(icon, size: iconSize, color: iconColor ?? textColor);
|
|
}
|
|
}
|