|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
import 'package:appinio_swiper/appinio_swiper.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/api/marathon/marathon_api_client.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/classes/consts.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/marathon/marathon_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/marathon/question_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart';
|
|
|
|
|
|
|
|
|
|
class MarathonProvider extends ChangeNotifier {
|
|
|
|
|
final AppinioSwiperController swiperController = AppinioSwiperController();
|
|
|
|
|
|
|
|
|
|
MarathonDetailModel marathonDetailModel = MarathonDetailModel();
|
|
|
|
|
List<CardContent> cardContentList = <CardContent>[
|
|
|
|
|
CardContent(question: ApiConsts.dummyQuestion),
|
|
|
|
|
CardContent(question: ApiConsts.dummyQuestion),
|
|
|
|
|
CardContent(question: ApiConsts.dummyQuestion),
|
|
|
|
|
CardContent(question: ApiConsts.dummyQuestion),
|
|
|
|
|
CardContent(question: ApiConsts.dummyQuestion),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
int currentGapTime = 0;
|
|
|
|
|
|
|
|
|
|
void addNewQuestionsToTheList(QuestionModel newQuestion, int index) {
|
|
|
|
|
|
|
|
|
|
//TODO: THIS SHOULD NOT SWIPE THE CARD ON THE FIRST TRIGGER
|
|
|
|
|
swipeCardLeft();
|
|
|
|
|
cardContentList.add(CardContent(question: newQuestion));
|
|
|
|
|
currentGapTime = newQuestion.nextQuestGap!;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void removeQuestionFromTheList(int index) {
|
|
|
|
|
cardContentList.removeAt(index);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
|
|
|
|
|
bool get isLoading => _isLoading;
|
|
|
|
|
|
|
|
|
|
set isLoading(bool value) {
|
|
|
|
|
_isLoading = value;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool _itsMarathonTime = false;
|
|
|
|
|
|
|
|
|
|
bool get itsMarathonTime => _itsMarathonTime;
|
|
|
|
|
|
|
|
|
|
set itsMarathonTime(bool value) {
|
|
|
|
|
_itsMarathonTime = value;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool _isMarathonCompleted = false;
|
|
|
|
|
|
|
|
|
|
bool get isMarathonCompleted => _isMarathonCompleted;
|
|
|
|
|
|
|
|
|
|
set isMarathonCompleted(bool value) {
|
|
|
|
|
_isMarathonCompleted = value;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int _currentQuestionNumber = 0;
|
|
|
|
|
|
|
|
|
|
int get currentQuestionNumber => _currentQuestionNumber;
|
|
|
|
|
|
|
|
|
|
set currentQuestionNumber(int value) {
|
|
|
|
|
_currentQuestionNumber = value;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int _totalMarathoners = 23;
|
|
|
|
|
|
|
|
|
|
int get totalMarathoners => _totalMarathoners;
|
|
|
|
|
|
|
|
|
|
set totalMarathoners(int value) {
|
|
|
|
|
_totalMarathoners = value;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void swipeCardLeft() {
|
|
|
|
|
swiperController.swipeLeft();
|
|
|
|
|
currentQuestionNumber++;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timer timerU = Timer.periodic(const Duration(seconds: 1), (Timer timer) {});
|
|
|
|
|
|
|
|
|
|
void startTimer(BuildContext context) {
|
|
|
|
|
const Duration oneSec = Duration(seconds: 1);
|
|
|
|
|
timerU = Timer.periodic(
|
|
|
|
|
oneSec,
|
|
|
|
|
(Timer timer) async {
|
|
|
|
|
if (currentGapTime == 0) {
|
|
|
|
|
// if (currentQuestionNumber == 9) {
|
|
|
|
|
// timer.cancel();
|
|
|
|
|
// cancelTimer();
|
|
|
|
|
// isMarathonCompleted = true;
|
|
|
|
|
// await Future<dynamic>.delayed(const Duration(seconds: 3)).whenComplete(
|
|
|
|
|
// () => Navigator.pushReplacementNamed(context, AppRoutes.marathonWinnerSelection),
|
|
|
|
|
// );
|
|
|
|
|
//
|
|
|
|
|
// resetValues();
|
|
|
|
|
//
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// timer.cancel();
|
|
|
|
|
} else {
|
|
|
|
|
currentGapTime--;
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void resetValues() {
|
|
|
|
|
_currentQuestionNumber = 0;
|
|
|
|
|
cardContentList.clear();
|
|
|
|
|
timerU.cancel();
|
|
|
|
|
_isMarathonCompleted = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cancelTimer() {
|
|
|
|
|
timerU.cancel();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> getMarathonDetailsFromApi() async {
|
|
|
|
|
isLoading = true;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
await MarathonApiClient().getMarathonToken().whenComplete(() async {
|
|
|
|
|
marathonDetailModel = await MarathonApiClient().getMarathonDetails();
|
|
|
|
|
isLoading = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> connectSignalrAndJoinMarathon(BuildContext context) async {
|
|
|
|
|
await MarathonApiClient().buildHubConnection(context);
|
|
|
|
|
}
|
|
|
|
|
}
|