TF-4141 Show AI action tag in list emails
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tmail_ui_user/features/base/widget/labels/tag_widget.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
class AiActionTagWidget extends StatelessWidget {
|
||||
final EdgeInsetsGeometry? margin;
|
||||
|
||||
const AiActionTagWidget({super.key, this.margin});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TagWidget(
|
||||
text: AppLocalizations.of(context).actionRequired,
|
||||
backgroundColor: AppColor.aiActionTag,
|
||||
textColor: Colors.white,
|
||||
isTruncateText: true,
|
||||
showTooltip: PlatformInfo.isWeb,
|
||||
margin: margin,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:core/presentation/utils/theme_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TagWidget extends StatelessWidget {
|
||||
final String text;
|
||||
final double horizontalPadding;
|
||||
final Color? backgroundColor;
|
||||
final Color? textColor;
|
||||
final double? maxWidth;
|
||||
final bool isTruncateText;
|
||||
final bool showTooltip;
|
||||
final EdgeInsetsGeometry? margin;
|
||||
|
||||
const TagWidget({
|
||||
super.key,
|
||||
required this.text,
|
||||
this.horizontalPadding = 4,
|
||||
this.isTruncateText = false,
|
||||
this.showTooltip = false,
|
||||
this.backgroundColor,
|
||||
this.textColor,
|
||||
this.maxWidth,
|
||||
this.margin,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget labelText = Text(
|
||||
isTruncateText ? _truncateName(text) : text,
|
||||
style: ThemeUtils.textStyleContentCaption().copyWith(
|
||||
color: textColor,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
);
|
||||
|
||||
if (showTooltip) {
|
||||
labelText = Tooltip(
|
||||
message: text,
|
||||
child: labelText,
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(4)),
|
||||
),
|
||||
constraints:
|
||||
maxWidth != null ? BoxConstraints(maxWidth: maxWidth!) : null,
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
||||
margin: margin,
|
||||
child: labelText,
|
||||
);
|
||||
}
|
||||
|
||||
String _truncateName(String name, {int maxLength = 16}) {
|
||||
try {
|
||||
if (name.length <= maxLength) return name;
|
||||
return '${name.substring(0, maxLength - 1)}...';
|
||||
} catch (_) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user