forked from Sub6Resources/flutter_html
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.dart
89 lines (77 loc) · 2.23 KB
/
utils.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import 'package:flutter/material.dart';
import 'package:flutter_html/src/style.dart';
Map<String, String> namedColors = {
"White": "#FFFFFF",
"Silver": "#C0C0C0",
"Gray": "#808080",
"Black": "#000000",
"Red": "#FF0000",
"Maroon": "#800000",
"Yellow": "#FFFF00",
"Olive": "#808000",
"Lime": "#00FF00",
"Green": "#008000",
"Aqua": "#00FFFF",
"Teal": "#008080",
"Blue": "#0000FF",
"Navy": "#000080",
"Fuchsia": "#FF00FF",
"Purple": "#800080",
};
class Context<T> {
T data;
Context(this.data);
}
// This class is a workaround so that both an image
// and a link can detect taps at the same time.
class MultipleTapGestureDetector extends InheritedWidget {
final void Function()? onTap;
const MultipleTapGestureDetector({
super.key,
required super.child,
required this.onTap,
});
static MultipleTapGestureDetector? of(BuildContext context) {
return context
.dependOnInheritedWidgetOfExactType<MultipleTapGestureDetector>();
}
@override
bool updateShouldNotify(MultipleTapGestureDetector oldWidget) => false;
}
class CustomBorderSide {
CustomBorderSide({
this.color = const Color(0xFF000000),
this.width = 1.0,
this.style = BorderStyle.none,
}) : assert(width >= 0.0);
Color? color;
double width;
BorderStyle style;
}
extension TextTransformUtil on String? {
String? transformed(TextTransform? transform) {
if (this == null) return null;
if (transform == TextTransform.uppercase) {
return this!.toUpperCase();
} else if (transform == TextTransform.lowercase) {
return this!.toLowerCase();
} else if (transform == TextTransform.capitalize) {
final stringBuffer = StringBuffer();
var capitalizeNext = true;
for (final letter in this!.toLowerCase().codeUnits) {
// UTF-16: A-Z => 65-90, a-z => 97-122.
if (capitalizeNext && letter >= 97 && letter <= 122) {
stringBuffer.writeCharCode(letter - 32);
capitalizeNext = false;
} else {
// UTF-16: 32 == space, 46 == period
if (letter == 32 || letter == 46) capitalizeNext = true;
stringBuffer.writeCharCode(letter);
}
}
return stringBuffer.toString();
} else {
return this;
}
}
}