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.
182 lines
5.4 KiB
Dart
182 lines
5.4 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mohem_flutter_app/api/etqan_ovr_api_client.dart';
|
|
import 'package:mohem_flutter_app/classes/utils.dart';
|
|
import 'package:mohem_flutter_app/models/etqan_ovr/etqan_get_employee_incident_report.dart';
|
|
import 'package:mohem_flutter_app/models/etqan_ovr/etqan_get_requests_model.dart';
|
|
import 'package:mohem_flutter_app/models/etqan_ovr/etqan_getprojects_model.dart';
|
|
import 'package:speech_to_text/speech_recognition_result.dart';
|
|
import 'package:speech_to_text/speech_to_text.dart';
|
|
|
|
class EtqanOvrProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
// Home screen state
|
|
List<EtqanGetProjectsResponse>? getEtqanProjectsList;
|
|
List<EtqanGetEmployeeOvrRequestsResponse>? getEtqanEmployeeRequestsList;
|
|
List<EtqanGetIncidentRequestResponse>? getEtqanEmployeeIncidnetRequest;
|
|
bool isLoading = false;
|
|
String? _ticketId;
|
|
|
|
// Speech to text state
|
|
final SpeechToText _speechToText = SpeechToText();
|
|
bool _speechEnabled = false;
|
|
bool _isListening = false;
|
|
|
|
// Getters for speech state
|
|
bool get speechEnabled => _speechEnabled;
|
|
|
|
bool get isListening => _isListening;
|
|
|
|
// Getter for ticketId
|
|
String get getTicketId => _ticketId ?? '';
|
|
|
|
// Setter for ticketId
|
|
void setTicketId(String ticketId) {
|
|
_ticketId = ticketId;
|
|
notifyListeners();
|
|
}
|
|
|
|
// Create request screen state
|
|
EtqanGetProjectsResponse? selectedProject;
|
|
String? selectedEmployeeNumber;
|
|
File? attachment;
|
|
String? attachmentBase64;
|
|
String description = '';
|
|
|
|
/// Initialize speech recognition - call this once when screen loads
|
|
Future<void> initSpeech() async {
|
|
_speechEnabled = await _speechToText.initialize();
|
|
notifyListeners();
|
|
}
|
|
|
|
/// Start listening for speech input
|
|
Future<void> startListening(String localeId, TextEditingController controller) async {
|
|
await _speechToText.listen(
|
|
onResult: (SpeechRecognitionResult result) {
|
|
description = result.recognizedWords;
|
|
controller.text = result.recognizedWords;
|
|
controller.selection = TextSelection.fromPosition(TextPosition(offset: controller.text.length));
|
|
notifyListeners();
|
|
},
|
|
localeId: localeId,
|
|
);
|
|
_isListening = true;
|
|
notifyListeners();
|
|
}
|
|
|
|
/// Stop listening for speech input
|
|
Future<void> stopListening() async {
|
|
await _speechToText.stop();
|
|
_isListening = false;
|
|
notifyListeners();
|
|
}
|
|
|
|
/// Toggle listening state
|
|
Future<void> toggleListening(String localeId, TextEditingController controller) async {
|
|
if (_isListening) {
|
|
await stopListening();
|
|
} else {
|
|
await startListening(localeId, controller);
|
|
}
|
|
}
|
|
|
|
// Fetch Etqan Projects
|
|
Future<void> fetchEtqanProjects(BuildContext context) async {
|
|
isLoading = true;
|
|
notifyListeners();
|
|
Utils.showLoading(context);
|
|
getEtqanProjectsList?.clear();
|
|
getEtqanProjectsList = await EtqanApiClient().getEtqanProjects();
|
|
Utils.hideLoading(context);
|
|
isLoading = false;
|
|
notifyListeners();
|
|
}
|
|
|
|
// Fetch Etqan Employee Requests
|
|
Future<void> fetchEtqanEmployeeRequests(BuildContext context) async {
|
|
isLoading = true;
|
|
notifyListeners();
|
|
Utils.showLoading(context);
|
|
getEtqanEmployeeRequestsList?.clear();
|
|
getEtqanEmployeeRequestsList = await EtqanApiClient().getEmployeeEtqanRequests();
|
|
Utils.hideLoading(context);
|
|
isLoading = false;
|
|
notifyListeners();
|
|
}
|
|
|
|
// Fetch Etqan Employee Incident Report
|
|
Future<void> fetchEtqanEmployeeIncidentRequests(BuildContext context, String ticketNo) async {
|
|
isLoading = true;
|
|
notifyListeners();
|
|
Utils.showLoading(context);
|
|
getEtqanEmployeeIncidnetRequest?.clear();
|
|
getEtqanEmployeeIncidnetRequest = await EtqanApiClient().getEtqanIncidentRequests(ticketNo);
|
|
Utils.hideLoading(context);
|
|
isLoading = false;
|
|
notifyListeners();
|
|
}
|
|
|
|
// Set selected project
|
|
void setSelectedProject(EtqanGetProjectsResponse? project) {
|
|
selectedProject = project;
|
|
notifyListeners();
|
|
}
|
|
|
|
// Set selected employee number
|
|
void setSelectedEmployeeNumber(String? employeeNumber) {
|
|
selectedEmployeeNumber = employeeNumber;
|
|
notifyListeners();
|
|
}
|
|
|
|
// Set attachment with base64
|
|
void setAttachment(File file, String base64) {
|
|
attachment = file;
|
|
attachmentBase64 = base64;
|
|
notifyListeners();
|
|
}
|
|
|
|
// Remove attachment
|
|
void removeAttachment() {
|
|
attachment = null;
|
|
attachmentBase64 = null;
|
|
notifyListeners();
|
|
}
|
|
|
|
// Set description
|
|
void setDescription(String value) {
|
|
description = value;
|
|
notifyListeners();
|
|
}
|
|
|
|
// Clear create request form
|
|
void clearCreateRequestForm() {
|
|
selectedProject = null;
|
|
selectedEmployeeNumber = null;
|
|
attachment = null;
|
|
attachmentBase64 = null;
|
|
description = '';
|
|
notifyListeners();
|
|
}
|
|
|
|
// Submit request
|
|
Future<bool> submitRequest(BuildContext context) async {
|
|
try {
|
|
Utils.showLoading(context);
|
|
int? isSuccess = await EtqanApiClient().createRequest(description, selectedProject?.projectId, attachmentBase64);
|
|
Utils.hideLoading(context);
|
|
if (isSuccess == 1) {
|
|
getEtqanEmployeeRequestsList = await EtqanApiClient().getEmployeeEtqanRequests();
|
|
notifyListeners();
|
|
Navigator.of(context).pop();
|
|
return true;
|
|
}
|
|
return false;
|
|
} catch (ex) {
|
|
Utils.hideLoading(context);
|
|
Utils.handleException(ex, context, null);
|
|
return false;
|
|
}
|
|
}
|
|
}
|