@@ -4,6 +4,12 @@ import 'package:intl/intl.dart';
4
4
5
5
import 'package:flutter_form_builder/flutter_form_builder.dart' ;
6
6
7
+ /// Configuration to what values show on sliders
8
+ ///
9
+ /// - `all` : Show all values
10
+ /// - `current` : Show only the current value (middle)
11
+ /// - `minMax` : Show only the min and max values (start and finish)
12
+ /// - `none` : No show any values
7
13
enum DisplayValues { all, current, minMax, none }
8
14
9
15
/// Field for selection of a numerical value on a slider
@@ -121,12 +127,68 @@ class FormBuilderSlider extends FormBuilderField<double> {
121
127
/// {@macro flutter.widgets.Focus.autofocus}
122
128
final bool autofocus;
123
129
124
- ///TODO: Add documentation
130
+ /// An alternative to displaying the text value of the slider.
131
+ ///
132
+ /// Defaults to null.
133
+ ///
134
+ /// When used [minValueWidget] will override the value for the minimum widget.
135
+ final Widget Function (String min)? minValueWidget;
136
+
137
+ /// An alternative to displaying the text value of the slider.
138
+ ///
139
+ /// Defaults to null.
140
+ ///
141
+ /// When used [valueWidget] will override the value for the selected value widget.
142
+ final Widget Function (String value)? valueWidget;
143
+
144
+ /// An alternative to displaying the text value of the slider.
145
+ ///
146
+ /// Defaults to null.
147
+ ///
148
+ /// When used [maxValueWidget] will override the value for the maximum widget.
149
+ final Widget Function (String max)? maxValueWidget;
150
+
151
+ /// Provides the ability to format a number in a locale-specific way.
152
+ ///
153
+ /// The format is specified as a pattern using a subset of the ICU formatting
154
+ /// patterns.
155
+ ///
156
+ /// - `0` A single digit
157
+ /// - `#` A single digit, omitted if the value is zero
158
+ /// - `.` Decimal separator
159
+ /// - `-` Minus sign
160
+ /// - `,` Grouping separator
161
+ /// - `E` Separates mantissa and expontent
162
+ /// - `+` - Before an exponent, to say it should be prefixed with a plus sign.
163
+ /// - `%` - In prefix or suffix, multiply by 100 and show as percentage
164
+ /// - `‰ (\u2030)` In prefix or suffix, multiply by 1000 and show as per mille
165
+ /// - `¤ (\u00A4)` Currency sign, replaced by currency name
166
+ /// - `'` Used to quote special characters
167
+ /// - `;` Used to separate the positive and negative patterns (if both present)
168
+ ///
169
+ /// For example,
170
+ ///
171
+ /// var f = NumberFormat("###.0#", "en_US");
172
+ /// print(f.format(12.345));
173
+ /// ==> 12.34
174
+ ///
175
+ /// If the locale is not specified, it will default to the current locale. If
176
+ /// the format is not specified it will print in a basic format with at least
177
+ /// one integer digit and three fraction digits.
178
+ ///
179
+ /// There are also standard patterns available via the special constructors.
180
+ /// e.g.
181
+ ///
182
+ /// var percent = NumberFormat.percentPattern("ar"); var
183
+ /// eurosInUSFormat = NumberFormat.currency(locale: "en_US",
184
+ /// symbol: "€");
185
+ ///
186
+ /// There are several such constructors available, though some of them are
187
+ /// limited. For example, at the moment, scientificPattern prints only as
188
+ /// equivalent to "#E0" and does not take into account significant digits.
125
189
final NumberFormat ? numberFormat;
190
+
126
191
final DisplayValues displayValues;
127
- final TextStyle ? minTextStyle;
128
- final TextStyle ? textStyle;
129
- final TextStyle ? maxTextStyle;
130
192
131
193
/// Creates field for selection of a numerical value on a slider
132
194
FormBuilderSlider ({
@@ -154,11 +216,11 @@ class FormBuilderSlider extends FormBuilderField<double> {
154
216
this .semanticFormatterCallback,
155
217
this .numberFormat,
156
218
this .displayValues = DisplayValues .all,
157
- this .minTextStyle,
158
- this .textStyle,
159
- this .maxTextStyle,
160
219
this .autofocus = false ,
161
220
this .mouseCursor,
221
+ this .maxValueWidget,
222
+ this .minValueWidget,
223
+ this .valueWidget,
162
224
}) : super (
163
225
builder: (FormFieldState <double ?> field) {
164
226
final state = field as _FormBuilderSliderState ;
@@ -196,24 +258,21 @@ class FormBuilderSlider extends FormBuilderField<double> {
196
258
children: < Widget > [
197
259
if (displayValues != DisplayValues .none &&
198
260
displayValues != DisplayValues .current)
199
- Text (
200
- effectiveNumberFormat.format (min),
201
- style: minTextStyle ?? textStyle,
202
- ),
261
+ minValueWidget
262
+ ? .call (effectiveNumberFormat.format (min)) ??
263
+ Text (effectiveNumberFormat.format (min)),
203
264
const Spacer (),
204
265
if (displayValues != DisplayValues .none &&
205
266
displayValues != DisplayValues .minMax)
206
- Text (
207
- effectiveNumberFormat.format (field.value),
208
- style: textStyle,
209
- ),
267
+ valueWidget? .call (
268
+ effectiveNumberFormat.format (field.value)) ??
269
+ Text (effectiveNumberFormat.format (field.value)),
210
270
const Spacer (),
211
271
if (displayValues != DisplayValues .none &&
212
272
displayValues != DisplayValues .current)
213
- Text (
214
- effectiveNumberFormat.format (max),
215
- style: maxTextStyle ?? textStyle,
216
- ),
273
+ maxValueWidget
274
+ ? .call (effectiveNumberFormat.format (max)) ??
275
+ Text (effectiveNumberFormat.format (max)),
217
276
],
218
277
),
219
278
],
0 commit comments