Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 49694d9

Browse files
committed
Fix setMinMax
1 parent 68a8b7f commit 49694d9

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

lib/src/cubit.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ class InteractiveTimelineCubit extends Cubit<InteractiveTimelineState> {
101101
}
102102
}
103103

104-
void setMinMax({DateTime? minCursor, DateTime? maxCursor}) {
104+
void setMinMax({DateTime? minCursor, DateTime? maxCursor, DateTime? middleCursor}) {
105105
var newState = state.setMinMaxCursor(minCursor: minCursor, maxCursor: maxCursor);
106106
newState = newState.overwrite(
107-
middleCursor: newState.cropMinMaxCursor(newState.middleCursor),
107+
// middleCursor is optional to use custom middleCursor to crop
108+
middleCursor: newState.cropMinMaxCursor(middleCursor ?? newState.middleCursor),
108109
);
109110
emit(newState);
110111
}
@@ -209,13 +210,13 @@ class InteractiveTimelineState extends Equatable {
209210
maxCursor ?? this.maxCursor,
210211
);
211212

212-
DateTime getLeftCursor(double width, double secondsPerPixel) {
213+
DateTime _calculateLeftCursor(double width, double secondsPerPixel, DateTime middleCursor) {
213214
return middleCursor.subtract(
214215
Duration(milliseconds: ((width / 2) * secondsPerPixel * 1000).toInt()),
215216
);
216217
}
217218

218-
DateTime getRightCursor(double width, double secondsPerPixel) {
219+
DateTime _calculateRightCursor(double width, double secondsPerPixel, DateTime middleCursor) {
219220
return middleCursor.add(
220221
Duration(milliseconds: ((width / 2) * secondsPerPixel * 1000).toInt()),
221222
);
@@ -255,15 +256,16 @@ class InteractiveTimelineState extends Equatable {
255256
double newSecondsPerScreenWidth = secondsPerScreenWidth ?? this.secondsPerScreenWidth;
256257
double newWidth = width ?? this.width;
257258
double newSecondsPerPixel = newSecondsPerScreenWidth / newWidth;
259+
DateTime newMiddleCursor = middleCursor ?? this.middleCursor;
258260
return InteractiveTimelineState(
259261
width: newWidth,
260262
height: height ?? this.height,
261263
secondsPerPixel: newSecondsPerPixel,
262264
secondsPerScreenWidth: newSecondsPerScreenWidth,
263265
secondsPerScreenWidthBeforeZoom: secondsPerScreenWidthBeforeZoom ?? this.secondsPerScreenWidthBeforeZoom,
264266
middleCursor: middleCursor ?? this.middleCursor,
265-
leftCursor: getLeftCursor(width ?? this.width, newSecondsPerPixel),
266-
rightCursor: getRightCursor(width ?? this.width, newSecondsPerPixel),
267+
leftCursor: _calculateLeftCursor(newWidth, newSecondsPerPixel, newMiddleCursor),
268+
rightCursor: _calculateRightCursor(newWidth, newSecondsPerPixel, newMiddleCursor),
267269
minCursor: minCursor ?? this.minCursor,
268270
maxCursor: maxCursor ?? this.maxCursor,
269271
playTimer: playTimer ?? this.playTimer,

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: interactive_timeline
22
description: Draggable and zoomable interactive timeline.
3-
version: 1.0.0-dev.4
3+
version: 1.0.0-dev.5
44
# homepage: https://www.example.com
55

66
environment:

0 commit comments

Comments
 (0)