2023-10-03 13:00:59 -04:00
|
|
|
import 'package:recon/config.dart';
|
2023-05-25 13:30:15 -04:00
|
|
|
import 'package:flutter/material.dart';
|
2023-04-30 03:01:59 -04:00
|
|
|
import 'package:path/path.dart' as p;
|
2023-05-02 12:22:18 -04:00
|
|
|
import 'package:html/parser.dart' as htmlparser;
|
2023-04-30 03:01:59 -04:00
|
|
|
|
2023-04-30 17:14:29 -04:00
|
|
|
class Aux {
|
2023-09-29 03:51:46 -04:00
|
|
|
static String resdbToHttp(String? resdb) {
|
|
|
|
if (resdb == null || resdb.isEmpty) return "";
|
|
|
|
if (resdb.startsWith("http")) return resdb;
|
|
|
|
final filename = p.basenameWithoutExtension(resdb);
|
2023-09-29 06:30:43 -04:00
|
|
|
return "${Config.skyfrostAssetsUrl}/$filename";
|
2023-04-30 17:14:29 -04:00
|
|
|
}
|
2023-05-01 12:50:54 -04:00
|
|
|
}
|
2023-05-02 04:04:54 -04:00
|
|
|
|
|
|
|
extension Unique<E, Id> on List<E> {
|
|
|
|
List<E> unique([Id Function(E element)? id, bool inplace = true]) {
|
|
|
|
final ids = <Id>{};
|
|
|
|
var list = inplace ? this : List<E>.from(this);
|
|
|
|
list.retainWhere((x) => ids.add(id != null ? id(x) : x as Id));
|
|
|
|
return list;
|
|
|
|
}
|
2023-05-02 12:22:18 -04:00
|
|
|
}
|
|
|
|
|
2023-05-17 02:10:52 -04:00
|
|
|
extension StringX on String {
|
2023-05-02 12:22:18 -04:00
|
|
|
String stripHtml() {
|
|
|
|
final document = htmlparser.parse(this);
|
|
|
|
return htmlparser.parse(document.body?.text).documentElement?.text ?? "";
|
|
|
|
}
|
2023-05-05 05:29:54 -04:00
|
|
|
|
2023-05-07 06:53:19 -04:00
|
|
|
// This won't be accurate since userIds can't contain certain characters that usernames can
|
|
|
|
// but it's fine for just having a name to display
|
2023-05-05 05:29:54 -04:00
|
|
|
String stripUid() => startsWith("U-") ? substring(2) : this;
|
2023-05-17 02:10:52 -04:00
|
|
|
|
|
|
|
String? get asNullable => isEmpty ? null : this;
|
2023-05-02 15:34:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
extension Format on Duration {
|
|
|
|
String format() {
|
|
|
|
final hh = (inHours).toString().padLeft(2, '0');
|
|
|
|
final mm = (inMinutes % 60).toString().padLeft(2, '0');
|
|
|
|
final ss = (inSeconds % 60).toString().padLeft(2, '0');
|
|
|
|
if (inHours == 0) {
|
|
|
|
return "$mm:$ss";
|
|
|
|
} else {
|
|
|
|
return "$hh:$mm:$ss";
|
|
|
|
}
|
|
|
|
}
|
2023-05-16 09:59:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
extension DateTimeX on DateTime {
|
|
|
|
static DateTime epoch = DateTime.fromMillisecondsSinceEpoch(0);
|
|
|
|
static DateTime one = DateTime(1);
|
2023-05-25 13:30:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
extension ColorX on Color {
|
|
|
|
Color invert() {
|
|
|
|
final r = 255 - red;
|
|
|
|
final g = 255 - green;
|
|
|
|
final b = 255 - blue;
|
|
|
|
|
|
|
|
return Color.fromARGB((opacity * 255).round(), r, g, b);
|
|
|
|
}
|
2023-05-02 04:04:54 -04:00
|
|
|
}
|