Files
Siro/siro_driver/lib/controller/home/captin/help/help_controller.dart
T

94 lines
2.3 KiB
Dart
Executable File

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../../constant/box_name.dart';
import '../../../../constant/links.dart';
import '../../../../main.dart';
import '../../../functions/crud.dart';
class HelpController extends GetxController {
bool isLoading = false;
final formKey = GlobalKey<FormState>();
final helpQuestionController = TextEditingController();
Map helpQuestionDate = {};
Map helpQuestionRepleyDate = {};
String status = '';
String qustion = '';
late int indexQuestion = 0;
Map<int, String> aiReplies = {};
getIndex(int i, String qustion1) async {
indexQuestion = i;
qustion = qustion1;
update();
}
void addHelpQuestion() async {
isLoading = true;
update();
var res = await CRUD().post(link: AppLink.addhelpCenter, payload: {
'driverID': box.read(BoxName.driverID).toString(),
'helpQuestion': (helpQuestionController.text)
});
var d = jsonDecode(res);
isLoading = false;
update();
if (d['status'].toString() == 'success') {
getHelpQuestion();
helpQuestionController.clear();
}
}
void getHelpQuestion() async {
getHelpQuestionFuture();
}
Future<void> getHelpQuestionFuture() async {
isLoading = true;
update();
var res = await CRUD().get(link: AppLink.gethelpCenter, payload: {
'driverID': box.read(BoxName.driverID).toString(),
});
if (res == "failure") {
isLoading = false;
helpQuestionDate = {'message': []};
update();
return;
}
helpQuestionDate = jsonDecode(res);
isLoading = false;
update();
}
Future getHelpRepley(String id) async {
isLoading = true;
update();
var res = await CRUD().get(link: AppLink.getByIdhelpCenter, payload: {
'id': id,
});
if (res == "failure") {
status = 'not yet';
isLoading = false;
update();
} else {
status = 'done';
helpQuestionRepleyDate = jsonDecode(res);
isLoading = false;
update();
}
}
@override
void onInit() {
final storedReplies = box.read<Map<String, dynamic>>('ai_replies') ?? {};
aiReplies = storedReplies
.map((key, value) => MapEntry(int.parse(key), value.toString()));
getHelpQuestion();
super.onInit();
}
}