I've got this code where I'm displaying multiple CheckboxListTile widgets on my screen. I need to create a controller for them, but I'm having some trouble. Could you help me? Thanks in advance. I have already the Model, entity, mapper and so on in order to use the Clean architecture.
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class ClinicHistoryController extends GetxController {
final ClinicHistoryRepository clinicHistoryImpl;
ClinicHistoryController(this.clinicHistoryImpl);
List<ClinicHistory> clinicHistoryList = [];
List<BoolItemElectronicFile> familyHeritageData = [
BoolItemElectronicFile(name: "Cancer", value: false),
BoolItemElectronicFile(name: "Cardiopatías", value: false),
BoolItemElectronicFile(name: "Diabetes", value: false),
BoolItemElectronicFile(name: "Hepatopatías", value: false),
BoolItemElectronicFile(name: "Hipertensión", value: false),
BoolItemElectronicFile(name: "Obesidad", value: false),
BoolItemElectronicFile(name: "Osteoporosis", value: false),
];
List<ItemElectronicFile> pathologiesdata = [
//items
];
List<ItemElectronicFile> symptomsPresentingdata = [
//items
];
MedicalTreatments medicalTreatmentsdata =
MedicalTreatments(medicalTreatments: " ");
PerformedSurgeries performedSurgeriesdata =
PerformedSurgeries(performedSurgeries: " ");
//moreitems
handleHereditarydata(dynamic newValue) {
familyHeritageData = newValue;
update();
}
handlesufferingPathologies(dynamic newValue) {
pathologiesdata = newValue;
update();
}
handlesymptoms(dynamic newValue) {
pathologiesdata = newValue;
update();
}
Future addClinicHistory() async {
final newClinicHistory = ClinicHistory(
familyHeritageData: familyHeritageData,
sufferingPathologies: pathologiesdata,
symptomsPresenting: symptomsPresentingdata,
medicalTreatments: medicalTreatmentsdata,
performedSurgeries: performedSurgeriesdata,
//moreitems
);
try {
await clinicHistoryImpl
.addClinicHistory(history: newClinicHistory, idUser: "ADFGSDF")
.then(
(value) => Get.snackbar("Nuevo metodo de pago", "Pago registrado.",
backgroundColor: Colors.green[100],
duration: const Duration(seconds: 5)),
);
update();
} catch (e) {
Get.snackbar('Invalido', 'Invalido',
backgroundColor: Colors.red[900],
duration: const Duration(seconds: 5));
}
}
}
This is the implementation file:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class ClinicHistoryDatasourceFirebase implements ClinicHistoryDataSource {
CollectionReference clinicHistoryref =
FirebaseFirestore.instance.collection('Expediente');
@override
Future addClinicHistory(
{required ClinicHistory history, required String idUser}) async {
await clinicHistoryref
.doc(idUser)
.set(ClinicHistoryFileMapper.toJson(history))
.whenComplete(() => Get.snackbar(
"Nuevo Expediente Electronico", "Expediente registrado.",
backgroundColor: Colors.green[100],
duration: const Duration(seconds: 5)))
.catchError((error, stackTrace) {
Get.snackbar("Error", "Intentalo de nuevo",
backgroundColor: Colors.red[900],
duration: const Duration(seconds: 5));
print(error.toString());
});
return clinicHistoryref;
}