@@ -53,7 +53,7 @@ class TokenField extends StatelessWidget {
53
53
filled: true ,
54
54
helper: range != null && showHelper
55
55
? _Helper (
56
- symbol : currency.symbol ,
56
+ currency : currency,
57
57
range: range,
58
58
)
59
59
: null ,
@@ -87,37 +87,58 @@ class TokenField extends StatelessWidget {
87
87
}
88
88
89
89
class _Helper extends StatelessWidget {
90
- final String symbol ;
90
+ final Currency currency ;
91
91
final Range <int > range;
92
92
93
93
const _Helper ({
94
- required this .symbol ,
94
+ required this .currency ,
95
95
required this .range,
96
96
});
97
97
98
98
@override
99
99
Widget build (BuildContext context) {
100
- // TODO(damian-molinski): Range can accept null as min/max
101
- // meaning they are unconstrained, handle it
102
- // TODO(damian-molinski): Refactor text formatting with smarter syntax
103
- return Text .rich (
104
- TextSpan (
105
- children: [
106
- TextSpan (text: context.l10n.requestedAmountShouldBeBetween),
107
- const TextSpan (text: ' ' ),
108
- TextSpan (
109
- text: '$symbol ${range .min }' ,
110
- style: const TextStyle (fontWeight: FontWeight .bold),
111
- ),
112
- const TextSpan (text: ' ' ),
113
- TextSpan (text: context.l10n.and),
114
- const TextSpan (text: ' ' ),
115
- TextSpan (
116
- text: '$symbol ${range .max }' ,
117
- style: const TextStyle (fontWeight: FontWeight .bold),
118
- ),
119
- ],
120
- ),
121
- );
100
+ final min = range.min;
101
+ final max = range.max;
102
+
103
+ const boldStyle = TextStyle (fontWeight: FontWeight .bold);
104
+
105
+ if (min != null && max != null ) {
106
+ return PlaceholderRichText (
107
+ context.l10n.requestedAmountShouldBeBetweenMinAndMax,
108
+ placeholderSpanBuilder: (context, placeholder) {
109
+ return switch (placeholder) {
110
+ 'min' => TextSpan (text: currency.format (min), style: boldStyle),
111
+ 'max' => TextSpan (text: currency.format (max), style: boldStyle),
112
+ _ => throw ArgumentError ('Unknown placeholder[$placeholder ]' ),
113
+ };
114
+ },
115
+ );
116
+ }
117
+
118
+ if (min != null ) {
119
+ return PlaceholderRichText (
120
+ context.l10n.requestedAmountShouldBeMoreThan,
121
+ placeholderSpanBuilder: (context, placeholder) {
122
+ return switch (placeholder) {
123
+ 'min' => TextSpan (text: currency.format (min), style: boldStyle),
124
+ _ => throw ArgumentError ('Unknown placeholder[$placeholder ]' ),
125
+ };
126
+ },
127
+ );
128
+ }
129
+
130
+ if (max != null ) {
131
+ return PlaceholderRichText (
132
+ context.l10n.requestedAmountShouldBeLessThan,
133
+ placeholderSpanBuilder: (context, placeholder) {
134
+ return switch (placeholder) {
135
+ 'max' => TextSpan (text: currency.format (max), style: boldStyle),
136
+ _ => throw ArgumentError ('Unknown placeholder[$placeholder ]' ),
137
+ };
138
+ },
139
+ );
140
+ }
141
+
142
+ return const Text ('' );
122
143
}
123
144
}
0 commit comments