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(); final helpQuestionController = TextEditingController(); Map helpQuestionDate = {}; Map helpQuestionRepleyDate = {}; String status = ''; String qustion = ''; late int indexQuestion = 0; Map 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 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>('ai_replies') ?? {}; aiReplies = storedReplies .map((key, value) => MapEntry(int.parse(key), value.toString())); getHelpQuestion(); super.onInit(); } }