You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hmg-mohemm-flutter-app/lib/ui/marathon/marathon_provider.dart

59 lines
1.4 KiB
Dart

import 'dart:async';
import 'package:appinio_swiper/appinio_swiper.dart';
import 'package:flutter/cupertino.dart';
import 'package:mohem_flutter_app/config/routes.dart';
class MarathonProvider extends ChangeNotifier {
final AppinioSwiperController swiperController = AppinioSwiperController();
bool _itsMarathonTime = false;
bool get itsMarathonTime => _itsMarathonTime;
set itsMarathonTime(bool value) {
_itsMarathonTime = value;
notifyListeners();
}
int _currentQuestionNumber = 1;
final int totalQuestions = 10;
int get currentQuestionNumber => _currentQuestionNumber;
set currentQuestionNumber(int value) {
_currentQuestionNumber = value;
notifyListeners();
}
Timer timer = Timer.periodic(const Duration(seconds: 1), (Timer timer) {});
int start = 5;
void startTimer(BuildContext context) {
start = 5;
const Duration oneSec = Duration(seconds: 1);
timer = Timer.periodic(
oneSec,
(Timer timer) {
if (start == 0) {
if (currentQuestionNumber == 10) {
timer.cancel();
Navigator.pushNamed(context, AppRoutes.marathonWinnerSelection);
}
swiperController.swipeLeft();
currentQuestionNumber = currentQuestionNumber + 1;
timer.cancel();
} else {
start--;
}
notifyListeners();
},
);
}
void cancelTimer() {
timer.cancel();
notifyListeners();
}
}