moving list view

This commit is contained in:
Joshua Burman
2024-12-07 23:32:56 -05:00
parent 4e5eeec937
commit 586d2355c9
6 changed files with 71 additions and 19 deletions

View File

@ -1,6 +1,7 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import 'package:sendtrain/models/activity_model.dart';
class ActivityTimerModel with ChangeNotifier {
@ -11,6 +12,7 @@ class ActivityTimerModel with ChangeNotifier {
int _currentSetNum = 0;
Timer? _periodicTimer;
double _progress = 0;
ItemScrollController? _isc;
int get actionCount => _actionCounter;
int get currentActionNum => _currentActionNum;
@ -24,11 +26,31 @@ class ActivityTimerModel with ChangeNotifier {
double get progress => _progress;
void setup(ActivityModel activity) {
_activity = activity;
_sets = activity.actions[0].items();
if (_activity == null || activity.id != _activity?.id) {
_periodicTimer?.cancel();
_progress = 0;
_isc = null;
_activity = activity;
_sets = activity.actions[0].items();
_currentActionNum = 0;
_currentSetNum = 0;
setActionCount();
}
moveToIndex(_currentSetNum);
}
void reset() {
_progress = 0;
_currentActionNum = 0;
_currentSetNum = 0;
_periodicTimer!.cancel();
setActionCount();
moveToIndex(0);
}
void setScrollController(ItemScrollController isc) {
_isc = isc;
}
bool isCurrentItem(int setNum, int actionNum) {
@ -79,13 +101,16 @@ class ActivityTimerModel with ChangeNotifier {
}
void updateProgress() {
_progress = (currentAction['actionID'] + (1.0 - _actionCounter / currentAction['amount'])) / totalActions();
_progress = (currentAction['actionID'] +
(1.0 - _actionCounter / currentAction['amount'])) /
totalActions();
notifyListeners();
}
void setAction(int setNum, int actionNum, String type) {
_currentActionNum = actionNum;
_currentSetNum = setNum;
moveToIndex(_currentSetNum);
notifyListeners();
}
@ -99,8 +124,16 @@ class ActivityTimerModel with ChangeNotifier {
} else {
// if we're done all the sets
// cancel timer and reset activity
_periodicTimer!.cancel();
setup(_activity!);
reset();
}
}
void moveToIndex(int index) {
if (_isc != null && _isc!.isAttached) {
_isc?.scrollTo(
index: index,
duration: Duration(milliseconds: 500),
curve: Curves.easeInOutCubic);
}
}