TF-4171 Display tag in mailbox list

This commit is contained in:
dab246
2025-11-25 14:02:50 +07:00
committed by Dat H. Pham
parent f4302e06e8
commit 31ed2feae4
19 changed files with 1865 additions and 38 deletions
+2
View File
@@ -18,6 +18,7 @@ export 'presentation/extensions/map_extensions.dart';
export 'presentation/extensions/either_view_state_extension.dart';
export 'presentation/extensions/media_type_extension.dart';
export 'presentation/extensions/scroll_controller_extension.dart';
export 'presentation/extensions/hex_color_extension.dart';
// Exceptions
export 'domain/exceptions/download_file_exception.dart';
@@ -63,6 +64,7 @@ export 'utils/web_link_generator.dart';
export 'utils/sentry/sentry_manager.dart';
export 'utils/config/env_loader.dart';
export 'utils/sentry/sentry_dio_helper.dart';
export 'utils/widget_utils.dart';
// Views
export 'presentation/views/text/slogan_builder.dart';
@@ -0,0 +1,18 @@
import 'package:flutter/material.dart';
extension HexColorExtension on String {
Color toColor({Color fallback = Colors.transparent}) {
try {
final hex = replaceAll('#', '');
if (hex.length != 6 && hex.length != 8) {
return fallback;
}
final fullHex = hex.length == 6 ? 'FF$hex' : hex;
return Color(int.parse(fullHex, radix: 16));
} catch (_) {
return fallback;
}
}
}
+33
View File
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
class WidgetUtils {
WidgetUtils._();
static double measureTextWidth({
required String text,
double fallbackWidth = 0,
TextStyle? style,
Locale? locale,
double? horizontalPadding,
}) {
try {
final textPainter = TextPainter(
text: TextSpan(
text: text,
style: style,
locale: locale,
),
maxLines: 1,
textDirection: TextDirection.ltr,
)..layout();
if (horizontalPadding != null) {
return textPainter.width + horizontalPadding * 2;
} else {
return textPainter.width;
}
} catch (e) {
return fallbackWidth;
}
}
}
@@ -0,0 +1,57 @@
import 'package:core/presentation/extensions/hex_color_extension.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('HexColorExtension.toColor', () {
test('should convert 6-char hex (#RRGGBB) to Color with default alpha FF',
() {
final color = "#FF0000".toColor();
expect(color, const Color(0xFFFF0000));
});
test('should convert 8-char hex (#AARRGGBB) correctly', () {
final color = "#80FF0000".toColor();
expect(color, const Color(0x80FF0000));
});
test('should handle string without # prefix', () {
final color = "00FF00".toColor();
expect(color, const Color(0xFF00FF00));
});
test('should return fallback when hex is invalid', () {
const fallback = Colors.blue;
final color = "INVALID".toColor(fallback: fallback);
expect(color, fallback);
});
test('should return fallback when hex contains non-hex characters', () {
const fallback = Colors.red;
final color = "#GGHHHH".toColor(fallback: fallback);
expect(color, fallback);
});
test('should return fallback when hex length is unsupported', () {
const fallback = Colors.orange;
final color = "#FFF".toColor(fallback: fallback);
expect(color, fallback);
});
test('should return fallback for empty string', () {
const fallback = Colors.purple;
final color = "".toColor(fallback: fallback);
expect(color, fallback);
});
test('should convert lowercase hex', () {
final color = "#ff0000".toColor();
expect(color, const Color(0xFFFF0000));
});
test('should convert mixed-case hex', () {
final color = "#Ff00Ff".toColor();
expect(color, const Color(0xFFFf00Ff));
});
});
}