Files
CityCards_Customer_Flutter/lib/common_packages/custom_text.dart

75 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
class CustomText extends StatelessWidget {
final FontWeight? weight;
final Color? color;
final double? size;
final String text;
final int? maxLines;
final TextOverflow? overflow;
final TextAlign? textAlign;
final Color asteriskColor; // ADD THIS
const CustomText({
Key? key,
this.weight,
this.color,
this.size,
required this.text,
this.maxLines,
this.overflow,
this.textAlign,
this.asteriskColor = Colors.red, // ADD THIS
}) : super(key: key);
@override
Widget build(BuildContext context) {
// ADD THIS BLOCK
if (asteriskColor != null && text.contains('*')) {
final parts = text.split('*');
return RichText(
text: TextSpan(
text: parts[0],
style: TextStyle(
fontWeight: weight,
color: color ?? Colors.black,
fontSize: size,
),
children: [
TextSpan(
text: '*',
style: TextStyle(
color: asteriskColor,
fontWeight: weight,
fontSize: size,
),
),
if (parts.length > 1) TextSpan(text: parts[1]),
],
),
maxLines: maxLines,
overflow: overflow ?? TextOverflow.clip,
textAlign: textAlign ?? TextAlign.start,
);
}
return Text(
text,
style: TextStyle(
fontWeight: FontWeight.lerp(
weight,
FontWeight.values[
(FontWeight.values.indexOf(weight ?? FontWeight.w400) + 1)
.clamp(0, FontWeight.values.length - 1)
],
0.5,
),
color: color,
fontSize: size,
),
maxLines: maxLines,
overflow: overflow,
textAlign: textAlign,
);
}
}