| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import 'dart:ui';
- extension HexColor on String {
- Color toColor() {
- final hexCode = replaceAll('#', '');
- return Color(int.parse('FF$hexCode', radix: 16));
- }
- }
- extension BoolExtension on bool? {
- bool get isTrue => this == true;
- bool get isFalse => this == false;
- }
- extension StringExtension on String? {
- String get orEmpty => this ?? '';
- }
- extension DurationExtension on double? {
- String toFormattedDuration() {
- if (this == null) return '';
- int totalSeconds = (this!).round();
- if (totalSeconds < 60) {
- return '${totalSeconds}s';
- } else if (totalSeconds < 3600) {
- int minutes = totalSeconds ~/ 60;
- int seconds = totalSeconds % 60;
- return '${minutes}m${seconds}s';
- } else {
- int hours = totalSeconds ~/ 3600;
- int minutes = (totalSeconds % 3600) ~/ 60;
- int seconds = totalSeconds % 60;
- return '${hours}h${minutes}m${seconds}s';
- }
- }
- }
- extension StringExtensions on String {
- String replacePlaceholders(List<dynamic> replacements) {
- var result = this;
- for (var replacement in replacements) {
- if (replacement is String) {
- result = result.replaceFirst('%s', replacement);
- } else if (replacement is int) {
- result = result.replaceFirst('%d', replacement.toString());
- }
- }
- return result;
- }
- }
|