137 lines
3.6 KiB
Dart
137 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import '../../../chatvibe_data/models/enum/at_vip_type.dart';
|
|
import 'at_marquee_gradient_text.dart';
|
|
|
|
final RegExp _nickNameEmojiRegex = RegExp(
|
|
r'[\u{1F000}-\u{1FAFF}\u{2600}-\u{27BF}\u{FE0F}\u{200D}]',
|
|
unicode: true,
|
|
);
|
|
|
|
Widget text(
|
|
String content, {
|
|
double fontSize = 12,
|
|
Color textColor = Colors.white,
|
|
int maxLines = 1,
|
|
TextDecoration decoration = TextDecoration.none,
|
|
FontWeight fontWeight = FontWeight.w400,
|
|
TextOverflow overflow = TextOverflow.ellipsis,
|
|
TextAlign? textAlign,
|
|
double? maxWidth,
|
|
double? letterSpacing,
|
|
double? lineHeight,
|
|
FontStyle? fontStyle,
|
|
List<Shadow>? shadows,
|
|
TextDirection? textDirection,
|
|
}) {
|
|
return Container(
|
|
constraints: BoxConstraints(maxWidth: maxWidth ?? double.infinity),
|
|
child: Text(
|
|
content,
|
|
overflow: overflow,
|
|
maxLines: maxLines,
|
|
textAlign: textAlign,
|
|
style: TextStyle(
|
|
fontSize: fontSize.sp,
|
|
color: textColor,
|
|
fontWeight: fontWeight,
|
|
decoration: decoration,
|
|
letterSpacing: letterSpacing,
|
|
height: lineHeight,
|
|
fontStyle: fontStyle,
|
|
shadows: shadows,
|
|
decorationThickness: 2,
|
|
decorationColor: textColor,
|
|
),
|
|
textDirection: textDirection,
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget chatvibeNickNameText(
|
|
String content, {
|
|
double fontSize = 12,
|
|
int maxLines = 1,
|
|
Color textColor = Colors.white,
|
|
double? maxWidth,
|
|
String? type,
|
|
bool needScroll = false,
|
|
bool pauseAnimation = false,
|
|
FontWeight fontWeight = FontWeight.w400,
|
|
double? speed,
|
|
double? sweepSpeed,
|
|
double? gapWidth,
|
|
}) {
|
|
if (content.isEmpty) {
|
|
return Container();
|
|
}
|
|
List<Color> gradientColors = [textColor, textColor];
|
|
bool isNeedGradient = false;
|
|
if (type == ATVIPType.VISCOUNT.name) {
|
|
textColor = Color(0xffFF7542);
|
|
gradientColors = [textColor, textColor];
|
|
} else if (type == ATVIPType.EARL.name) {
|
|
textColor = Color(0xff5E9AFA);
|
|
gradientColors = [textColor, textColor];
|
|
} else if (type == ATVIPType.MARQUIS.name) {
|
|
textColor = Color(0xff1CC483);
|
|
gradientColors = [textColor, textColor];
|
|
} else if (type == ATVIPType.DUKE.name) {
|
|
gradientColors = [
|
|
Color(0xffCC97EF),
|
|
Color(0xffAC60EA),
|
|
Color(0xffA42EE9),
|
|
Color(0xff961CCA),
|
|
Color(0xff601393),
|
|
];
|
|
isNeedGradient = true;
|
|
} else if (type == ATVIPType.KING.name) {
|
|
gradientColors = [
|
|
Color(0xffEF9897),
|
|
Color(0xffEA6160),
|
|
Color(0xffE9372E),
|
|
Color(0xffCA271C),
|
|
Color(0xff931913),
|
|
];
|
|
isNeedGradient = true;
|
|
} else if (type == ATVIPType.EMPEROR.name) {
|
|
gradientColors = [
|
|
Color(0xffF54EA3),
|
|
Color(0xffF64389),
|
|
Color(0xffF7666C),
|
|
Color(0xffF6805D),
|
|
Color(0xffF0C956),
|
|
Color(0xffCCE077),
|
|
Color(0xff9BE094),
|
|
Color(0xff5DDBCD),
|
|
Color(0xff0098F7),
|
|
Color(0xff1E6CEF),
|
|
Color(0xff5535B8),
|
|
];
|
|
isNeedGradient = true;
|
|
}
|
|
|
|
final bool hasEmoji = _nickNameEmojiRegex.hasMatch(content);
|
|
if (hasEmoji && isNeedGradient && gradientColors.isNotEmpty) {
|
|
textColor = gradientColors[gradientColors.length ~/ 2];
|
|
}
|
|
|
|
return Container(
|
|
constraints: maxWidth != null ? BoxConstraints(maxWidth: maxWidth) : null,
|
|
child: ATMarqueeGradientText(
|
|
gradientColors: gradientColors,
|
|
text: content,
|
|
fontSize: fontSize,
|
|
fontWeight: fontWeight,
|
|
needScroll: needScroll,
|
|
pauseAnimation: pauseAnimation,
|
|
sweepSpeed: sweepSpeed ?? 1.0,
|
|
speed: speed ?? 20,
|
|
gapWidth: gapWidth ?? 100,
|
|
textColor: textColor,
|
|
needGradient: isNeedGradient && !hasEmoji,
|
|
),
|
|
);
|
|
}
|