2026-07-01 18:25:58 +08:00

776 lines
22 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:extended_image/extended_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:aslan/chatvibe_ui/components/text/at_text.dart';
import 'package:aslan/chatvibe_ui/theme/chatvibe_theme.dart';
import 'package:tancent_vap/utils/constant.dart';
import 'package:tancent_vap/widgets/vap_view.dart';
import 'package:aslan/chatvibe_data/sources/local/file_cache_manager.dart';
import 'package:aslan/chatvibe_ui/widgets/headdress/headdress_widget.dart';
import 'package:aslan/chatvibe_core/constants/at_global_config.dart';
import 'package:aslan/chatvibe_core/constants/at_screen.dart';
import 'package:aslan/chatvibe_core/utilities/at_path_utils.dart';
import '../../chatvibe_data/models/enum/at_room_roles_type.dart';
import '../../chatvibe_data/models/enum/at_vip_type.dart';
Widget head({
required String url,
required double width,
double? height,
Border? border,
String? headdress,
BoxShape shape = BoxShape.circle,
BoxFit fit = BoxFit.cover,
BorderRadius? borderRadius,
bool showDefault = true,
bool isRoom = false,
}) {
final double outerHeight = height ?? width;
final double avatarWidth = width * 0.76;
final double avatarHeight = outerHeight * 0.76;
final String imagePathForExt = Uri.tryParse(url)?.path ?? url;
final bool isGifAvatar =
ATPathUtils.fetchFileExtensionFunction(imagePathForExt) == ".gif";
Widget buildAvatarPlaceholder(String assetPath) {
return Image.asset(
assetPath,
width: avatarWidth,
height: avatarHeight,
fit: BoxFit.cover,
);
}
Widget buildStaticAvatar() {
return ExtendedImage.network(
url,
width: avatarWidth,
height: avatarHeight,
fit: fit,
cache: true,
clearMemoryCacheWhenDispose: false,
clearMemoryCacheIfFailed: true,
loadStateChanged: (ExtendedImageState state) {
if (state.extendedImageLoadState == LoadState.completed) {
return ExtendedRawImage(
image: state.extendedImageInfo?.image,
width: avatarWidth,
height: avatarHeight,
fit: fit,
);
} else if (state.extendedImageLoadState == LoadState.loading) {
return showDefault
? buildAvatarPlaceholder("atu_images/general/at_icon_loading.png")
: Container();
} else {
return buildAvatarPlaceholder(
"atu_images/general/at_icon_avar_defalt.png",
);
}
},
);
}
Widget buildGifAvatar() {
return Image.network(
url,
width: avatarWidth,
height: avatarHeight,
fit: fit,
gaplessPlayback: true,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) {
return child;
}
return showDefault
? buildAvatarPlaceholder("atu_images/general/at_icon_loading.png")
: Container();
},
errorBuilder: (context, error, stackTrace) {
return buildAvatarPlaceholder(
"atu_images/general/at_icon_avar_defalt.png",
);
},
);
}
Widget avatarChild = isGifAvatar ? buildGifAvatar() : buildStaticAvatar();
Widget clippedAvatar;
if (shape == BoxShape.circle) {
clippedAvatar = ClipOval(child: avatarChild);
} else if (borderRadius != null) {
clippedAvatar = ClipRRect(borderRadius: borderRadius, child: avatarChild);
} else {
clippedAvatar = ClipRect(child: avatarChild);
}
return RepaintBoundary(
child: Stack(
alignment: Alignment.center,
children: [
SizedBox(
width: width,
height: outerHeight,
child: Center(
child: Container(
width: avatarWidth,
height: avatarHeight,
decoration: BoxDecoration(
shape: shape,
border: border,
borderRadius: shape == BoxShape.rectangle ? borderRadius : null,
),
child: clippedAvatar,
),
),
),
headdress != null && ATPathUtils.fileTypeIsPicOperation(headdress)
? netImage(url: headdress, width: width, height: width)
: Container(),
headdress != null &&
ATPathUtils.fetchFileExtensionFunction(
headdress,
).toLowerCase() ==
".svga" &&
ATGlobalConfig.sdkInt > ATGlobalConfig.maxSdkNoAnim
? IgnorePointer(
child: SVGAHeadwearWidget(
width: width,
height: width,
resource: headdress,
),
)
: Container(),
headdress != null &&
ATPathUtils.fetchFileExtensionFunction(
headdress,
).toLowerCase() ==
".mp4" &&
ATGlobalConfig.sdkInt > ATGlobalConfig.maxSdkNoAnim
? SizedBox(
width: width,
height: width,
child: IgnorePointer(
child: VapView(
scaleType: ScaleType.centerCrop,
repeat: 90000000,
onViewCreated: (controller) {
FileCacheManager.getInstance().getFile(url: headdress).then(
(file) {
controller.playFile(file.path);
},
);
},
),
),
)
: Container(),
],
),
);
}
Widget netImage({
required String url,
String? defaultImg,
bool noDefaultImg = false,
double? width,
double? height,
BorderRadius? borderRadius,
BoxFit? fit,
BoxShape? shape,
Border? border,
}) {
// print('${ATGlobalConfig.imgHost}$image?imageslim');
if (ATPathUtils.fetchFileExtensionFunction(url).toLowerCase() == ".svga") {
return SVGAHeadwearWidget(
width: width,
height: height ?? width,
resource: url,
);
}
return ExtendedImage.network(
url,
width: width,
height: height ?? width,
fit: fit ?? BoxFit.cover,
cache: true,
shape: shape ?? BoxShape.rectangle,
borderRadius: borderRadius,
clearMemoryCacheWhenDispose: false,
clearMemoryCacheIfFailed: true,
border: border,
gaplessPlayback: true,
loadStateChanged: (ExtendedImageState state) {
if (state.extendedImageLoadState == LoadState.completed) {
return ExtendedRawImage(
image: state.extendedImageInfo?.image,
fit: fit ?? BoxFit.cover,
);
} else if (state.extendedImageLoadState == LoadState.failed) {
return noDefaultImg
? Container()
: Image.asset(
defaultImg ?? "atu_images/general/at_icon_loading.png",
fit: BoxFit.cover,
);
} else {
return noDefaultImg
? Container()
: Image.asset(
defaultImg ?? "atu_images/general/at_icon_loading.png",
fit: BoxFit.cover,
);
}
},
);
}
/// 空页面
///默认空页面
mainEmpty({
String msg = "No data",
Widget? image,
bool center = true,
Color textColor = const Color(0xff4d4d4d),
}) {
List<Widget> list = [];
list.add(SizedBox(height: height(center ? 40.w : 0.w)));
list.add(
image ??
Image.asset(
'atu_images/general/at_icon_no_data_icon.png',
width: 121.w,
fit: BoxFit.fitWidth,
),
);
list.add(SizedBox(height: height(10.w)));
list.add(
Text(
msg,
style: TextStyle(
fontSize: sp(12),
color: textColor,
fontWeight: FontWeight.w400,
decoration: TextDecoration.none,
height: 1,
),
),
);
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment:
center ? MainAxisAlignment.center : MainAxisAlignment.start,
children: list,
),
],
);
}
msgRoleTag(String role, {double? width, double? height}) {
String image = "";
if (ATRoomRolesType.HOMEOWNER.name == role) {
image = 'fz';
} else if (ATRoomRolesType.ADMIN.name == role) {
image = "gly";
} else if (ATRoomRolesType.MEMBER.name == role) {
image = "hy";
} else if (ATRoomRolesType.TOURIST.name == role) {
image = "guest";
}
if (image.isEmpty) return SizedBox.shrink();
return Container(
alignment: Alignment.center,
width: width ?? 22.w,
height: height ?? 22.w,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("atu_images/room/at_icon_room_$image.png"),
),
),
);
}
///性别 0女 1男
xb(num? sex, {double? height, Color? color = Colors.white}) {
// print('sex$sex');
// if (sex == null) return Container();
String image = "atu_images/login/at_icon_sex_man.png";
if (sex == 0) {
image = "atu_images/login/at_icon_sex_woman.png";
}
return Image.asset(
image,
height: height ?? 14.w,
fit: BoxFit.fill,
color: color,
);
}
xb2(num? sex, {double? width, double? height}) {
// print('sex$sex');
if (sex == null) return Container();
String image = "atu_images/login/at_icon_sex_man_bg.png";
if (sex == 0) {
image = "atu_images/login/at_icon_sex_woman_bg.png";
}
return Image.asset(
image,
width: width ?? 28.w,
height: height ?? 14.w,
fit: BoxFit.fill,
);
}
///搜索框
searchWidget({
Function? onChange,
Function? onTap,
String? hint,
double? hintSize,
Color? borderColor,
EdgeInsetsGeometry? padding,
TextEditingController? controller,
Color? textColor,
Color? serachIconColor,
FocusNode? focusNode,
}) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
if (onTap != null) {
onTap();
}
},
child: Container(
margin:
padding ??
EdgeInsetsDirectional.only(start: width(15), end: width(0)),
alignment: AlignmentDirectional.centerStart,
height: width(36),
//width: width(345),
decoration: BoxDecoration(
color: Color(0xFFF2F2F2),
borderRadius: BorderRadius.all(Radius.circular(height(20))),
border: Border.all(color: borderColor ?? Colors.black12, width: 1.w),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(width: width(10)),
Image.asset(
"atu_images/index/at_icon_serach2.png",
width: 20.w,
height: 20.w,
),
SizedBox(width: width(6)),
_buildPhoneInput(
onChange,
onTap == null,
hint ?? 'Search by ID',
controller,
textColor,
hintSize,
focusNode,
),
],
),
),
);
}
_buildPhoneInput(
Function? onChange,
bool enabled,
String tint,
TextEditingController? controller,
Color? textColor,
double? hintSize,
FocusNode? focusNode,
) {
return Expanded(
child: TextField(
controller: controller,
onChanged: (text) {
if (onChange != null) {
onChange(text);
}
},
focusNode: focusNode,
autofocus: false,
enabled: enabled,
maxLength: 11,
cursorColor: ChatVibeTheme.primaryColor,
decoration: InputDecoration(
hintText: tint,
hintStyle: TextStyle(
color: ChatVibeTheme.textSecondary,
fontSize: hintSize ?? sp(14),
),
counterText: '',
isDense: true,
filled: false,
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
disabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
focusedErrorBorder: InputBorder.none,
contentPadding: EdgeInsets.only(bottom: 0),
),
style: TextStyle(
textBaseline: TextBaseline.alphabetic,
fontSize: hintSize ?? sp(14),
color: textColor ?? Colors.black,
),
),
);
}
///vip标识
getVIPBadge(String? type, {double? width, double? height}) {
String icon = "";
if (type == ATVIPType.VISCOUNT.name) {
icon = "atu_images/vip/at_icon_vip1_badge.png";
} else if (type == ATVIPType.EARL.name) {
icon = "atu_images/vip/at_icon_vip2_badge.png";
} else if (type == ATVIPType.MARQUIS.name) {
icon = "atu_images/vip/at_icon_vip3_badge.png";
} else if (type == ATVIPType.DUKE.name) {
icon = "atu_images/vip/at_icon_vip4_badge.png";
} else if (type == ATVIPType.KING.name) {
icon = "atu_images/vip/at_icon_vip5_badge.png";
} else if (type == ATVIPType.EMPEROR.name) {
icon = "atu_images/vip/at_icon_vip6_badge.png";
}
return icon.isNotEmpty
? Image.asset(icon, width: width, height: height, fit: BoxFit.cover)
: Container();
}
///用户等级
getUserLevel(num level, {double? width, double? height, double? fontSize}) {
String icon = "";
if (level > 0 && level < 11) {
icon = "atu_images/level/at_icon_user_level_1_10.png";
} else if (level > 10 && level < 21) {
icon = "atu_images/level/at_icon_user_level_10_20.png";
} else if (level > 20 && level < 31) {
icon = "atu_images/level/at_icon_user_level_20_30.png";
} else if (level > 30 && level < 41) {
icon = "atu_images/level/at_icon_user_level_30_40.png";
} else if (level > 40 && level < 51) {
icon = "atu_images/level/at_icon_user_level_40_50.png";
}
return icon.isNotEmpty
? Directionality(
textDirection: TextDirection.ltr,
child: Stack(
alignment: AlignmentDirectional.center,
children: [
Image.asset(icon, width: width, height: height, fit: BoxFit.fill),
PositionedDirectional(
end: level > 9 ? 10.w : 15.w,
child: text(
"$level",
fontSize: fontSize ?? 12.sp,
fontWeight: FontWeight.w600,
),
),
],
),
)
: Container();
}
///用户魅力等级
getWealthLevel(num level, {double? width, double? height, double? fontSize}) {
String icon = "";
if (level > 0 && level < 11) {
icon = "atu_images/level/at_icon_wealth_level_1_10.png";
} else if (level > 10 && level < 21) {
icon = "atu_images/level/at_icon_wealth_level_10_20.png";
} else if (level > 20 && level < 31) {
icon = "atu_images/level/at_icon_wealth_level_20_30.png";
} else if (level > 30 && level < 41) {
icon = "atu_images/level/at_icon_wealth_level_30_40.png";
} else if (level > 40 && level < 51) {
icon = "atu_images/level/at_icon_wealth_level_40_50.png";
}
return icon.isNotEmpty
? Directionality(
textDirection: TextDirection.ltr,
child: Stack(
alignment: AlignmentDirectional.center,
children: [
Image.asset(icon, width: width, height: height, fit: BoxFit.fill),
PositionedDirectional(
end: level > 9 ? 10.w : 15.w,
child: text(
"$level",
fontSize: fontSize ?? 12.sp,
fontWeight: FontWeight.w600,
),
),
],
),
)
: Container();
}
getIdIcon(
num wealthLevel, {
double? width,
double? height,
Color textColor = Colors.white,
double fontSize = 12,
FontWeight fontWeight = FontWeight.w600,
}) {
String icon = "";
if (wealthLevel < 11) {
icon = "";
} else if (wealthLevel > 10 && wealthLevel < 21) {
icon = "atu_images/level/at_icon_wealth_id_icon_1.png";
} else if (wealthLevel > 20 && wealthLevel < 31) {
icon = "atu_images/level/at_icon_wealth_id_icon_2.png";
} else if (wealthLevel > 30 && wealthLevel < 41) {
icon = "atu_images/level/at_icon_wealth_id_icon_3.png";
} else if (wealthLevel > 40 && wealthLevel < 51) {
icon = "atu_images/level/at_icon_wealth_id_icon_4.png";
}
return icon.isNotEmpty
? Image.asset(icon, width: width, height: height)
: Container(
child: text(
"ID:",
fontSize: fontSize,
fontWeight: fontWeight,
textColor: textColor,
),
);
}
String getGiftObtCoinsBg(num obtCoins) {
String icon = "";
if (obtCoins > -1 && obtCoins < 5000) {
icon = "atu_images/room/at_icon_luck_gift_obt_coins_bg_0.png";
} else if (obtCoins > 4999 && obtCoins < 50000) {
icon = "atu_images/room/at_icon_luck_gift_obt_coins_bg_1.png";
} else if (obtCoins > 49999 && obtCoins < 100000) {
icon = "atu_images/room/at_icon_luck_gift_obt_coins_bg_2.png";
} else if (obtCoins > 99999 && obtCoins < 1000000) {
icon = "atu_images/room/at_icon_luck_gift_obt_coins_bg_3.png";
} else if (obtCoins > 999999 && obtCoins < 10000000) {
icon = "atu_images/room/at_icon_luck_gift_obt_coins_bg_4.png";
} else if (obtCoins > 9999999) {
icon = "atu_images/room/at_icon_luck_gift_obt_coins_bg_5.png";
}
return icon;
}
///数字图片
buildNum(String num, {double? size = 18}) {
if (num.isNotEmpty) {
List<Widget> eList = [];
int index = 0;
num.split("").forEach((item) {
if (item == "k") {
eList.add(
Container(
margin: EdgeInsetsDirectional.only(
start: (index * (size ?? 18) * 0.9).w,
),
child: Image.asset(
"atu_images/room/at_icon_k.png",
width: size,
height: size,
),
),
);
} else if (item == "m") {
eList.add(
Container(
margin: EdgeInsetsDirectional.only(
start: (index * (size ?? 18) * 0.9).w,
),
child: Image.asset(
"atu_images/room/at_icon_m.png",
width: size,
height: size,
),
),
);
} else {
eList.add(
Container(
margin: EdgeInsetsDirectional.only(
start: (index * (size ?? 18) * 0.8).w,
),
child: Image.asset(
"atu_images/room/at_icon_number_$item.png",
width: size,
height: size,
),
),
);
}
index = index + 1;
});
return Directionality(
textDirection: TextDirection.ltr,
child: Stack(children: eList),
);
} else {
return Container();
}
}
///游戏飘屏数字图片
buildNumForGame(String num, {double? size = 18}) {
if (num.isNotEmpty) {
List<Widget> eList = [];
int index = 0;
num.split("").forEach((item) {
if (item == "k") {
eList.add(
Container(
margin: EdgeInsetsDirectional.only(
start: (index * (size ?? 18) * 0.65).w,
),
child: Image.asset(
"atu_images/general/at_icon_game_numk.png",
width: size,
height: size,
),
),
);
} else if (item == "m") {
eList.add(
Container(
margin: EdgeInsetsDirectional.only(
start: (index * (size ?? 18) * 0.65).w,
),
child: Image.asset(
"atu_images/general/at_icon_game_numm.png",
width: size,
height: size,
),
),
);
} else {
eList.add(
Container(
margin: EdgeInsetsDirectional.only(
start: (index * (size ?? 18) * 0.6).w,
),
child: Image.asset(
"atu_images/general/at_icon_game_num$item.png",
width: size,
height: size,
),
),
);
}
index = index + 1;
});
return Directionality(
textDirection: TextDirection.ltr,
child: Stack(children: eList),
);
} else {
return Container();
}
}
///房间幸运数字
buildNumForRoomLuckNum(String num, {double? size = 18}) {
if (num.isNotEmpty) {
List<Widget> eList = [];
int index = 0;
num.split("").forEach((item) {
eList.add(
Container(
margin: EdgeInsetsDirectional.only(
start: (index * (size ?? 18) * 0.7).w,
),
child: Image.asset(
"atu_images/room/at_icon_lucknumber_$item.png",
width: size,
height: size,
),
),
);
index = index + 1;
});
return Directionality(
textDirection: TextDirection.ltr,
child: Stack(children: eList),
);
} else {
return Container();
}
}
buildFamilyProgressLinearGradient(int level) {
if (level == 0) {
return LinearGradient(colors: [Color(0xff2E4957), Color(0xffC9E7E8)]);
} else if (level == 1) {
return LinearGradient(colors: [Color(0xff5A3F31), Color(0xffF8CD85)]);
} else if (level == 2) {
return LinearGradient(colors: [Color(0xff0D5ACE), Color(0xffCBD9E8)]);
} else if (level == 3) {
return LinearGradient(colors: [Color(0xffC57E1C), Color(0xffCBD9E8)]);
} else if (level == 10) {
return LinearGradient(colors: [Color(0xff3C7FBE), Color(0xffADE1F1)]);
} else if (level == 11) {
return LinearGradient(colors: [Color(0xff300A67), Color(0xffA53EFF)]);
}
return LinearGradient(colors: [Color(0xff2E4957), Color(0xffC9E7E8)]);
}
buildVipNameColor(String type) {
List<Color>? gradientColors;
if (type == ATVIPType.DUKE.name) {
gradientColors = [
Color(0xffBFFDF8),
Color(0xff95E6EA),
Color(0xff63D1D0),
Color(0xff3FC5BE),
Color(0xff22B5AF),
];
} else if (type == ATVIPType.KING.name) {
gradientColors = [
Color(0xffEF9897),
Color(0xffEA6160),
Color(0xffE9372E),
Color(0xffCA271C),
Color(0xff931913),
];
} else if (type == ATVIPType.KING.name) {
gradientColors = [
Color(0xffF54EA3),
Color(0xffF64389),
Color(0xffF7666C),
Color(0xffF6805D),
Color(0xffF0C956),
Color(0xffCCE077),
Color(0xff9BE094),
Color(0xff5DDBCD),
Color(0xff0098F7),
Color(0xff1E6CEF),
Color(0xff5535B8),
];
}
return gradientColors;
}