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
49 changes: 26 additions & 23 deletions lib/seekbar/seekbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ abstract class BasicSeekbar extends StatefulWidget {
final String semanticsValue;

///进度改变的回调
final ValueChanged<ProgressValue> onValueChanged;
final void Function(ProgressValue value, bool isEnd) onValueChanged;
// final void Function(double) onValueChanged;

///进度条是否是圆角的,还是方形的,默认是圆角的
Expand Down Expand Up @@ -564,7 +564,7 @@ class SeekBar extends BasicSeekbar {
bool isCanTouch;
SeekBar({
Key key,
ValueChanged<ProgressValue> onValueChanged,
void Function(ProgressValue value, bool isEnd) onValueChanged,
double min,
double max,
double progresseight,
Expand Down Expand Up @@ -777,7 +777,7 @@ class _SeekBarState extends State<SeekBar> {
setState(() {
touchPoint = new Offset(
renderBox.globalToLocal(tapDetails.globalPosition).dx, 0.0);
_setValue(touchPoint.dx);
_setValue(touchPoint.dx, true);
if (widget.alwaysShowBubble != null && widget.alwaysShowBubble
? false
: true) {
Expand Down Expand Up @@ -850,37 +850,40 @@ class _SeekBarState extends State<SeekBar> {
if (widget.afterDragShowSectionText ?? false) {
_afterDragShowSectionText = true;
}
_setValue(-1, true);
});
}

void _setValue(double newValue) {
//这个是当前的进度 从0-1
_value = newValue / context.size.width;

//这个�����值��能在这个地方获取,如果没有指定,就是容器的��度
if (sectionCount > 1) {
for (var i = 0; i < sectionCount; i++) {
if (_value >= i * e && _value <= (i + 1) * e) {
start = i * e;
if (i == sectionCount) {
end = sectionCount * e;
} else {
end = (i + 1) * e;
void _setValue(double newValue, [bool isEnd = false]) {
if (!isEnd) {
//这个是当前的进度 从0-1
_value = newValue / context.size.width;

//这个�����值��能在这个地方获取,如果没有指定,就是容器的��度
if (sectionCount > 1) {
for (var i = 0; i < sectionCount; i++) {
if (_value >= i * e && _value <= (i + 1) * e) {
start = i * e;
if (i == sectionCount) {
end = sectionCount * e;
} else {
end = (i + 1) * e;
}
break;
}
break;
}
}
if (_value >= start + e / 2) {
_value = end;
} else {
_value = start;
if (_value >= start + e / 2) {
_value = end;
} else {
_value = start;
}
}
}
double realValue = length * _value + _min; //真实的值

if (widget.onValueChanged != null) {
ProgressValue v = ProgressValue(progress: _value, value: realValue);
widget.onValueChanged(v);
widget.onValueChanged(v, isEnd);
}
}

Expand Down