Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion lib/animated_weight_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,16 @@ class AnimatedWeightPicker extends StatefulWidget {
///
final Function(String newValue)? onChange;

/// Initial value of a weight picker/value picker
/// it's determine the initial position of picker
/// ```dart
///
/// 'Added by @prasetya4di'
/// ```
/// https://www.gurutechnolabs.com/
/// Web & App Development Company
final double? initialValue;

/// ```dart
///
/// 'Developed by GuruTechnolabs'
Expand Down Expand Up @@ -476,6 +486,8 @@ class AnimatedWeightPicker extends StatefulWidget {
this.suffix,
//
this.onChange,
//
this.initialValue,
}) : assert(!(max < min)),
assert(!(min == max)),
assert(!(max < 1)),
Expand All @@ -495,7 +507,9 @@ class AnimatedWeightPicker extends StatefulWidget {
assert(!(minorIntervalTextSize > 20 || minorIntervalTextSize < 1)),
assert(!(subIntervalTextSize > 20 || subIntervalTextSize < 1)),
assert(!(division < 0.1 || division > 1)),
assert(squeeze > 0);
assert(squeeze > 0),
assert(!(initialValue != null &&
(initialValue < min || initialValue > max)));

@override
State<AnimatedWeightPicker> createState() => _AnimatedWeightPickerState();
Expand All @@ -508,6 +522,8 @@ class _AnimatedWeightPickerState extends State<AnimatedWeightPicker> {
final List<WheelModel> _valueList = [];
int _selectedIndex = 0;

late final FixedExtentScrollController _scrollController;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -545,7 +561,15 @@ class _AnimatedWeightPickerState extends State<AnimatedWeightPicker> {

currentIndex++;
current += interval;

if (widget.initialValue != null &&
current.toPrecision(_valuePrecision) == widget.initialValue) {
_selectedIndex = currentIndex;
}
} while (current.toPrecision(2) <= widget.max);

_scrollController =
FixedExtentScrollController(initialItem: _selectedIndex);
if (!onInit) setState(() {});
}

Expand All @@ -570,6 +594,8 @@ class _AnimatedWeightPickerState extends State<AnimatedWeightPicker> {
child: RotatedBox(
quarterTurns: -45,
child: ListWheelScrollView.useDelegate(
physics: const FixedExtentScrollPhysics(),
controller: _scrollController,
offAxisFraction: 2,
perspective: 0.003,
itemExtent: 30,
Expand Down