|
|
|
|
@ -7,7 +7,6 @@ import 'package:mohem_flutter_app/api/api_client.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/classes/consts.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/classes/utils.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/toast/app_toast.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/config/routes.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/marathon/marathon_generic_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/marathon/marathon_model.dart';
|
|
|
|
|
@ -105,24 +104,18 @@ class MarathonApiClient {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<QuestionModel> getNextQuestion({required String? questionId, required String marathonId}) async {
|
|
|
|
|
Map<String, String?> jsonObject = <String, String?>{
|
|
|
|
|
"previousQuestionId": questionId,
|
|
|
|
|
"marathonId": marathonId,
|
|
|
|
|
};
|
|
|
|
|
Map<String, String?> jsonObject = <String, String?>{"previousQuestionId": questionId, "marathonId": marathonId};
|
|
|
|
|
|
|
|
|
|
return await ApiClient().postJsonForObject(
|
|
|
|
|
(json) {
|
|
|
|
|
MarathonGenericModel marathonModel = MarathonGenericModel.fromJson(json);
|
|
|
|
|
|
|
|
|
|
if (marathonModel.statusCode == 404 || marathonModel.statusCode == 208 || marathonModel.statusCode == 204 || marathonModel.statusCode == 500) {
|
|
|
|
|
AppToast.show(
|
|
|
|
|
Utils.showToast(
|
|
|
|
|
marathonModel.message!,
|
|
|
|
|
seconds: AppToast.actionSeconds,
|
|
|
|
|
onComplete: () {
|
|
|
|
|
AppRoutes.navigatorKey.currentContext!.read<MarathonProvider>().resetValues();
|
|
|
|
|
Navigator.of(
|
|
|
|
|
AppRoutes.navigatorKey.currentContext!,
|
|
|
|
|
).popUntil(ModalRoute.withName(AppRoutes.dashboard));
|
|
|
|
|
Navigator.of(AppRoutes.navigatorKey.currentContext!).popUntil(ModalRoute.withName(AppRoutes.dashboard));
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@ -215,99 +208,99 @@ class MarathonApiClient {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// late HubConnection hubConnection;
|
|
|
|
|
// Future<void> buildHubConnection(BuildContext context, String prizeId) async {
|
|
|
|
|
// HttpConnectionOptions httpOptions = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true);
|
|
|
|
|
// hubConnection = HubConnectionBuilder()
|
|
|
|
|
// .withUrl(
|
|
|
|
|
// ApiConsts.marathonHubConnectionUrl + "?employeeNumber=${AppState().memberInformationList!.eMPLOYEENUMBER ?? ""}&employeeName=${AppState().memberInformationList!.eMPLOYEENAME ?? ""}",
|
|
|
|
|
// options: httpOptions,
|
|
|
|
|
// )
|
|
|
|
|
// .withAutomaticReconnect(
|
|
|
|
|
// retryDelays: <int>[2000, 5000, 10000, 20000],
|
|
|
|
|
// )
|
|
|
|
|
// .configureLogging(
|
|
|
|
|
// Logger("Logging"),
|
|
|
|
|
// )
|
|
|
|
|
// .build();
|
|
|
|
|
// hubConnection.onclose(
|
|
|
|
|
// ({Exception? error}) {
|
|
|
|
|
// logger.i("onclose");
|
|
|
|
|
// },
|
|
|
|
|
// );
|
|
|
|
|
// hubConnection.onreconnecting(
|
|
|
|
|
// ({Exception? error}) {
|
|
|
|
|
// logger.i("onreconnecting");
|
|
|
|
|
// },
|
|
|
|
|
// );
|
|
|
|
|
// hubConnection.onreconnected(
|
|
|
|
|
// ({String? connectionId}) {
|
|
|
|
|
// logger.i("onreconnected");
|
|
|
|
|
// },
|
|
|
|
|
// );
|
|
|
|
|
// if (hubConnection.state != HubConnectionState.Connected) {
|
|
|
|
|
// await hubConnection.start();
|
|
|
|
|
// logger.i("Started HubConnection");
|
|
|
|
|
//
|
|
|
|
|
// await hubConnection.invoke(
|
|
|
|
|
// "AddParticipant",
|
|
|
|
|
// args: <Object>[
|
|
|
|
|
// <String, dynamic>{
|
|
|
|
|
// "employeeNumber": AppState().memberInformationList!.eMPLOYEENUMBER ?? "",
|
|
|
|
|
// "employeeName": AppState().memberInformationList!.eMPLOYEENAME ?? "",
|
|
|
|
|
// "marathonId": AppState().getMarathonProjectId,
|
|
|
|
|
// "prizeId": "8577B2E8-5DD7-43F0-10DD-08DACB0AC064",
|
|
|
|
|
// }
|
|
|
|
|
// ],
|
|
|
|
|
// ).catchError((e) {
|
|
|
|
|
// logger.i("Error in AddParticipant: $e");
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// context.read<MarathonProvider>().addItemToList(ApiConsts.dummyQuestion);
|
|
|
|
|
//
|
|
|
|
|
// await hubConnection.invoke(
|
|
|
|
|
// "SendQuestionToParticipant",
|
|
|
|
|
// args: <Object>[
|
|
|
|
|
// <String, dynamic>{
|
|
|
|
|
// "marathonId": "${AppState().getMarathonProjectId}",
|
|
|
|
|
// }
|
|
|
|
|
// ],
|
|
|
|
|
// ).catchError((e) {
|
|
|
|
|
// Utils.confirmDialog(context, e.toString());
|
|
|
|
|
// logger.i("Error in SendQuestionToParticipant: $e");
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// try {
|
|
|
|
|
// hubConnection.on("OnSendQuestionToParticipant", (List<Object?>? arguments) {
|
|
|
|
|
// onSendQuestionToParticipant(arguments, context);
|
|
|
|
|
// });
|
|
|
|
|
// } catch (e, s) {
|
|
|
|
|
// logger.i("Error in OnSendQuestionToParticipant");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// try {
|
|
|
|
|
// hubConnection.on("OnParticipantJoin", (List<Object?>? arguments) {
|
|
|
|
|
// onParticipantJoin(arguments, context);
|
|
|
|
|
// });
|
|
|
|
|
// } catch (e, s) {
|
|
|
|
|
// logger.i("Error in OnParticipantJoin");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Future<void> onSendQuestionToParticipant(List<Object?>? arguments, BuildContext context) async {
|
|
|
|
|
// logger.i("onSendQuestionToParticipant arguments: $arguments");
|
|
|
|
|
//
|
|
|
|
|
// if (arguments != null) {
|
|
|
|
|
// Map<dynamic, dynamic> data = arguments.first! as Map<dynamic, dynamic>;
|
|
|
|
|
// var json = data["data"];
|
|
|
|
|
// QuestionModel newQuestion = QuestionModel.fromJson(json);
|
|
|
|
|
// AppRoutes.navigatorKey.currentContext!.read<MarathonProvider>().onNewQuestionReceived(newQuestion);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Future<void> onParticipantJoin(List<Object?>? arguments, BuildContext context) async {
|
|
|
|
|
// logger.i("OnParticipantJoin arguments: $arguments");
|
|
|
|
|
// context.watch<MarathonProvider>().totalMarathoners++;
|
|
|
|
|
// }
|
|
|
|
|
// late HubConnection hubConnection;
|
|
|
|
|
// Future<void> buildHubConnection(BuildContext context, String prizeId) async {
|
|
|
|
|
// HttpConnectionOptions httpOptions = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true);
|
|
|
|
|
// hubConnection = HubConnectionBuilder()
|
|
|
|
|
// .withUrl(
|
|
|
|
|
// ApiConsts.marathonHubConnectionUrl + "?employeeNumber=${AppState().memberInformationList!.eMPLOYEENUMBER ?? ""}&employeeName=${AppState().memberInformationList!.eMPLOYEENAME ?? ""}",
|
|
|
|
|
// options: httpOptions,
|
|
|
|
|
// )
|
|
|
|
|
// .withAutomaticReconnect(
|
|
|
|
|
// retryDelays: <int>[2000, 5000, 10000, 20000],
|
|
|
|
|
// )
|
|
|
|
|
// .configureLogging(
|
|
|
|
|
// Logger("Logging"),
|
|
|
|
|
// )
|
|
|
|
|
// .build();
|
|
|
|
|
// hubConnection.onclose(
|
|
|
|
|
// ({Exception? error}) {
|
|
|
|
|
// logger.i("onclose");
|
|
|
|
|
// },
|
|
|
|
|
// );
|
|
|
|
|
// hubConnection.onreconnecting(
|
|
|
|
|
// ({Exception? error}) {
|
|
|
|
|
// logger.i("onreconnecting");
|
|
|
|
|
// },
|
|
|
|
|
// );
|
|
|
|
|
// hubConnection.onreconnected(
|
|
|
|
|
// ({String? connectionId}) {
|
|
|
|
|
// logger.i("onreconnected");
|
|
|
|
|
// },
|
|
|
|
|
// );
|
|
|
|
|
// if (hubConnection.state != HubConnectionState.Connected) {
|
|
|
|
|
// await hubConnection.start();
|
|
|
|
|
// logger.i("Started HubConnection");
|
|
|
|
|
//
|
|
|
|
|
// await hubConnection.invoke(
|
|
|
|
|
// "AddParticipant",
|
|
|
|
|
// args: <Object>[
|
|
|
|
|
// <String, dynamic>{
|
|
|
|
|
// "employeeNumber": AppState().memberInformationList!.eMPLOYEENUMBER ?? "",
|
|
|
|
|
// "employeeName": AppState().memberInformationList!.eMPLOYEENAME ?? "",
|
|
|
|
|
// "marathonId": AppState().getMarathonProjectId,
|
|
|
|
|
// "prizeId": "8577B2E8-5DD7-43F0-10DD-08DACB0AC064",
|
|
|
|
|
// }
|
|
|
|
|
// ],
|
|
|
|
|
// ).catchError((e) {
|
|
|
|
|
// logger.i("Error in AddParticipant: $e");
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// context.read<MarathonProvider>().addItemToList(ApiConsts.dummyQuestion);
|
|
|
|
|
//
|
|
|
|
|
// await hubConnection.invoke(
|
|
|
|
|
// "SendQuestionToParticipant",
|
|
|
|
|
// args: <Object>[
|
|
|
|
|
// <String, dynamic>{
|
|
|
|
|
// "marathonId": "${AppState().getMarathonProjectId}",
|
|
|
|
|
// }
|
|
|
|
|
// ],
|
|
|
|
|
// ).catchError((e) {
|
|
|
|
|
// Utils.confirmDialog(context, e.toString());
|
|
|
|
|
// logger.i("Error in SendQuestionToParticipant: $e");
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// try {
|
|
|
|
|
// hubConnection.on("OnSendQuestionToParticipant", (List<Object?>? arguments) {
|
|
|
|
|
// onSendQuestionToParticipant(arguments, context);
|
|
|
|
|
// });
|
|
|
|
|
// } catch (e, s) {
|
|
|
|
|
// logger.i("Error in OnSendQuestionToParticipant");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// try {
|
|
|
|
|
// hubConnection.on("OnParticipantJoin", (List<Object?>? arguments) {
|
|
|
|
|
// onParticipantJoin(arguments, context);
|
|
|
|
|
// });
|
|
|
|
|
// } catch (e, s) {
|
|
|
|
|
// logger.i("Error in OnParticipantJoin");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Future<void> onSendQuestionToParticipant(List<Object?>? arguments, BuildContext context) async {
|
|
|
|
|
// logger.i("onSendQuestionToParticipant arguments: $arguments");
|
|
|
|
|
//
|
|
|
|
|
// if (arguments != null) {
|
|
|
|
|
// Map<dynamic, dynamic> data = arguments.first! as Map<dynamic, dynamic>;
|
|
|
|
|
// var json = data["data"];
|
|
|
|
|
// QuestionModel newQuestion = QuestionModel.fromJson(json);
|
|
|
|
|
// AppRoutes.navigatorKey.currentContext!.read<MarathonProvider>().onNewQuestionReceived(newQuestion);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Future<void> onParticipantJoin(List<Object?>? arguments, BuildContext context) async {
|
|
|
|
|
// logger.i("OnParticipantJoin arguments: $arguments");
|
|
|
|
|
// context.watch<MarathonProvider>().totalMarathoners++;
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|