File tree Expand file tree Collapse file tree 3 files changed +66
-23
lines changed Expand file tree Collapse file tree 3 files changed +66
-23
lines changed Original file line number Diff line number Diff line change 1
- import 'package:flutter/widgets.dart' ;
2
-
3
1
extension StringExNullable on String ? {
4
2
bool get isNullOrEmpty => this == null || this ! .isEmpty;
5
3
@@ -27,27 +25,6 @@ extension StringEx on String {
27
25
}
28
26
}
29
27
30
- bool isWithinMaxLines (
31
- {required int maxLines,
32
- required double maxWidth,
33
- double minWidth = 0.0 ,
34
- TextStyle style = const TextStyle ()}) {
35
- if (isNullOrBlank) {
36
- return false ;
37
- }
38
-
39
- final text = TextSpan (text: this , style: style);
40
- final textPainter = TextPainter (
41
- maxLines: maxLines,
42
- textAlign: TextAlign .left,
43
- textDirection: TextDirection .ltr,
44
- text: text,
45
- );
46
-
47
- textPainter.layout (minWidth: minWidth, maxWidth: maxWidth);
48
- return textPainter.didExceedMaxLines;
49
- }
50
-
51
28
String withDate (String date) => replaceAll ('[DATE]' , date);
52
29
53
30
String withNumber (num number) => replaceAll ('[NUMBER]' , number.toString ());
Original file line number Diff line number Diff line change
1
+ // A set of extensions that can be used on the presentation layer.
2
+ library presentation_extensions;
3
+
4
+ export 'string_presentation_extensions.dart' ;
Original file line number Diff line number Diff line change
1
+ import 'package:flutter/widgets.dart' ;
2
+ import 'package:flutter_template/extensions/string_extensions.dart' ;
3
+
4
+ extension StringPresentationExtensions on String {
5
+ TextPainter _getTextPainter ({
6
+ TextStyle style = const TextStyle (),
7
+ int maxLines = 1 ,
8
+ double minWidth = .0 ,
9
+ double maxWidth = double .infinity,
10
+ }) {
11
+ final text = TextSpan (text: this , style: style);
12
+ final textPainter = TextPainter (
13
+ maxLines: maxLines,
14
+ textAlign: TextAlign .left,
15
+ textDirection: TextDirection .ltr,
16
+ text: text,
17
+ );
18
+
19
+ textPainter.layout (minWidth: minWidth, maxWidth: maxWidth);
20
+ return textPainter;
21
+ }
22
+
23
+ Size getSize (
24
+ TextStyle style, {
25
+ int maxLines = 1 ,
26
+ double minWidth = .0 ,
27
+ double maxWidth = double .infinity,
28
+ }) {
29
+ if (isNullOrBlank) {
30
+ return Size .zero;
31
+ }
32
+
33
+ final textPainter = _getTextPainter (
34
+ style: style,
35
+ maxLines: maxLines,
36
+ maxWidth: maxWidth,
37
+ minWidth: minWidth,
38
+ );
39
+
40
+ return textPainter.size;
41
+ }
42
+
43
+ bool isWithinMaxLines ({
44
+ required int maxLines,
45
+ required double maxWidth,
46
+ double minWidth = 0.0 ,
47
+ TextStyle style = const TextStyle (),
48
+ }) {
49
+ if (isNullOrBlank) {
50
+ return false ;
51
+ }
52
+
53
+ final textPainter = _getTextPainter (
54
+ style: style,
55
+ maxLines: maxLines,
56
+ maxWidth: maxWidth,
57
+ minWidth: minWidth,
58
+ );
59
+
60
+ return textPainter.didExceedMaxLines;
61
+ }
62
+ }
You can’t perform that action at this time.
0 commit comments