chatapp3-flutter/lib/ui_kit/widgets/id/sc_special_id_badge.dart
NIGGER SLAYER c4e177dd7e bug fix
2026-04-21 18:25:03 +08:00

146 lines
4.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:yumi/ui_kit/widgets/svga/sc_svga_asset_widget.dart';
class SCSpecialIdAssets {
static const String roomId = 'sc_images/general/room_id.svga';
static const String roomOwnerId = 'sc_images/general/room_id_custom.svga';
static const String userId = 'sc_images/general/user_id.svga';
static const String userIdLarge = 'sc_images/general/user_id_4.svga';
}
class SCSpecialIdBadge extends StatelessWidget {
const SCSpecialIdBadge({
super.key,
required this.idText,
this.showAnimated = false,
this.assetPath,
this.animationWidth = 120,
this.animationHeight = 28,
this.textPadding = EdgeInsets.zero,
this.animationTextStyle,
this.normalTextStyle,
this.normalPrefix = 'ID:',
this.showCopyIcon = false,
this.copyIconAssetPath = 'sc_images/room/sc_icon_user_card_copy_id.png',
this.copyIconSize = 12,
this.copyIconSpacing = 5,
this.copyIconColor,
this.loop = true,
this.active = true,
this.animationFit = BoxFit.fill,
});
final String idText;
final bool showAnimated;
final String? assetPath;
final double animationWidth;
final double animationHeight;
final EdgeInsetsGeometry textPadding;
final TextStyle? animationTextStyle;
final TextStyle? normalTextStyle;
final String normalPrefix;
final bool showCopyIcon;
final String copyIconAssetPath;
final double copyIconSize;
final double copyIconSpacing;
final Color? copyIconColor;
final bool loop;
final bool active;
final BoxFit animationFit;
@override
Widget build(BuildContext context) {
final normalizedId = idText.trim();
final shouldAnimate =
showAnimated &&
(assetPath?.isNotEmpty ?? false) &&
normalizedId.isNotEmpty;
final children = <Widget>[
shouldAnimate
? _buildAnimatedBadge(normalizedId)
: _buildPlainBadge(normalizedId),
];
if (showCopyIcon) {
children.add(SizedBox(width: copyIconSpacing));
children.add(
Image.asset(
copyIconAssetPath,
width: copyIconSize,
height: copyIconSize,
color: copyIconColor,
),
);
}
return Row(
mainAxisSize: MainAxisSize.min,
textDirection: TextDirection.ltr,
children: children,
);
}
Widget _buildAnimatedBadge(String normalizedId) {
return SizedBox(
width: animationWidth,
height: animationHeight,
child: Stack(
clipBehavior: Clip.none,
children: [
Positioned.fill(
child: SCSvgaAssetWidget(
assetPath: assetPath!,
width: animationWidth,
height: animationHeight,
active: active,
loop: loop,
fit: animationFit,
fallback: const SizedBox.shrink(),
),
),
Positioned.fill(
child: Padding(
padding: textPadding,
child: Align(
alignment: Alignment.centerLeft,
child: FittedBox(
fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft,
child: Text(
normalizedId,
maxLines: 1,
overflow: TextOverflow.visible,
style:
animationTextStyle ??
const TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w700,
),
),
),
),
),
),
],
),
);
}
Widget _buildPlainBadge(String normalizedId) {
return Text(
'$normalPrefix$normalizedId',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style:
normalTextStyle ??
const TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w600,
),
);
}
}