Skip to content

Commit

Permalink
Fix setMinMax
Browse files Browse the repository at this point in the history
  • Loading branch information
1cedsoda committed Sep 19, 2022
1 parent 68a8b7f commit 49694d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions lib/src/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ class InteractiveTimelineCubit extends Cubit<InteractiveTimelineState> {
}
}

void setMinMax({DateTime? minCursor, DateTime? maxCursor}) {
void setMinMax({DateTime? minCursor, DateTime? maxCursor, DateTime? middleCursor}) {
var newState = state.setMinMaxCursor(minCursor: minCursor, maxCursor: maxCursor);
newState = newState.overwrite(
middleCursor: newState.cropMinMaxCursor(newState.middleCursor),
// middleCursor is optional to use custom middleCursor to crop
middleCursor: newState.cropMinMaxCursor(middleCursor ?? newState.middleCursor),
);
emit(newState);
}
Expand Down Expand Up @@ -209,13 +210,13 @@ class InteractiveTimelineState extends Equatable {
maxCursor ?? this.maxCursor,
);

DateTime getLeftCursor(double width, double secondsPerPixel) {
DateTime _calculateLeftCursor(double width, double secondsPerPixel, DateTime middleCursor) {
return middleCursor.subtract(
Duration(milliseconds: ((width / 2) * secondsPerPixel * 1000).toInt()),
);
}

DateTime getRightCursor(double width, double secondsPerPixel) {
DateTime _calculateRightCursor(double width, double secondsPerPixel, DateTime middleCursor) {
return middleCursor.add(
Duration(milliseconds: ((width / 2) * secondsPerPixel * 1000).toInt()),
);
Expand Down Expand Up @@ -255,15 +256,16 @@ class InteractiveTimelineState extends Equatable {
double newSecondsPerScreenWidth = secondsPerScreenWidth ?? this.secondsPerScreenWidth;
double newWidth = width ?? this.width;
double newSecondsPerPixel = newSecondsPerScreenWidth / newWidth;
DateTime newMiddleCursor = middleCursor ?? this.middleCursor;
return InteractiveTimelineState(
width: newWidth,
height: height ?? this.height,
secondsPerPixel: newSecondsPerPixel,
secondsPerScreenWidth: newSecondsPerScreenWidth,
secondsPerScreenWidthBeforeZoom: secondsPerScreenWidthBeforeZoom ?? this.secondsPerScreenWidthBeforeZoom,
middleCursor: middleCursor ?? this.middleCursor,
leftCursor: getLeftCursor(width ?? this.width, newSecondsPerPixel),
rightCursor: getRightCursor(width ?? this.width, newSecondsPerPixel),
leftCursor: _calculateLeftCursor(newWidth, newSecondsPerPixel, newMiddleCursor),
rightCursor: _calculateRightCursor(newWidth, newSecondsPerPixel, newMiddleCursor),
minCursor: minCursor ?? this.minCursor,
maxCursor: maxCursor ?? this.maxCursor,
playTimer: playTimer ?? this.playTimer,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: interactive_timeline
description: Draggable and zoomable interactive timeline.
version: 1.0.0-dev.4
version: 1.0.0-dev.5
# homepage: https://www.example.com

environment:
Expand Down

0 comments on commit 49694d9

Please sign in to comment.