71 lines
1.9 KiB
Dart
71 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
|
|
import 'package:ftc_mobile_app/models/profileData/user_data.dart';
|
|
import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart';
|
|
import 'package:get/get.dart';
|
|
import '../../models/clients/recent_incidents_model.dart';
|
|
|
|
class RecentIncidentsScreenController extends GetxController {
|
|
final GlobalKey<ScaffoldState> screenKey = GlobalKey<ScaffoldState>();
|
|
|
|
final searchTEC = TextEditingController();
|
|
|
|
List<RecentIncidentsModel> oRecentIncidentsList = [];
|
|
|
|
RxList<RecentIncidentsModel> recentIncidentsList = RxList();
|
|
final serviceUser = Rx<UserData?>(null);
|
|
|
|
RecentIncidentsScreenController(UserData data) {
|
|
serviceUser(data);
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
fetchRecentIncidentList();
|
|
super.onReady();
|
|
}
|
|
|
|
void fetchRecentIncidentList() async {
|
|
if (serviceUser() == null) {
|
|
return;
|
|
}
|
|
|
|
var result = await ClientService()
|
|
.getRecentIncidentsListService(userId: serviceUser()!.id!)
|
|
.showLoader();
|
|
if (result is List<RecentIncidentsModel>) {
|
|
oRecentIncidentsList = List.from(result);
|
|
recentIncidentsList.value = result;
|
|
} else {
|
|
FrequentFunctions.showToast(message: result.toString());
|
|
}
|
|
}
|
|
|
|
void removeFocus() {
|
|
FocusScope.of(screenKey.currentContext!).unfocus();
|
|
}
|
|
|
|
onSearch(String text) {
|
|
if (text.isEmpty) {
|
|
recentIncidentsList.value = oRecentIncidentsList;
|
|
} else {
|
|
recentIncidentsList.value = oRecentIncidentsList
|
|
.where(
|
|
(e) => e.incidentTitle.toLowerCase().contains(text.toLowerCase()))
|
|
.toList();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
searchTEC.dispose();
|
|
Get.delete<RecentIncidentsScreenController>();
|
|
super.dispose();
|
|
}
|
|
|
|
void onBackPress(BuildContext context) {
|
|
Get.delete<RecentIncidentsScreenController>();
|
|
Navigator.pop(context);
|
|
}
|
|
}
|