import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:onemd/widget/fx_doctor_address.dart'; import 'fx_company_lookup.dart'; import 'fx_doctor_lookup.dart'; import 'fx_mitra_mou.dart'; import 'fx_text_field.dart'; import 'provider/mitra_add_provider.dart'; import 'provider/selectedCompanyProvider.dart'; import 'provider/selectedDoctorProvider.dart'; class FxMitraAddDialog extends HookConsumerWidget { const FxMitraAddDialog({Key? key}) : super(key: key); @override Widget build(BuildContext context, WidgetRef ref) { final fcLogin = FocusNode(); final company = ref.watch(selectedAcCompanyProvider); final doctor = ref.watch(selectedAcDoctorProvider); final doctorAddress = ref.watch(selectedAcDoctorAddressProvider); final mou = ref.watch(selectedMouProvider); final errorCompany = useState(null); final errorDoctor = useState(null); final errorDoctorAddress = useState(null); final errorMou = useState(null); final errorLogin = useState(null); final fcPassword = FocusNode(); final fcRePassword = FocusNode(); final errorPassword = useState(null); final errorRePassword = useState(null); final ctrlLogin = useTextEditingController(text: ""); final ctrlPassword = useTextEditingController(text: ""); final ctrlRePassword = useTextEditingController(text: ""); bool Function() validationError; validationError = () { bool haveError = false; if (ctrlPassword.text == "") { errorPassword.value = "Password is mandatory"; haveError = true; } if (ctrlRePassword.text != ctrlPassword.text) { errorRePassword.value = "Password confirmation error"; haveError = true; } if (company == null) { errorCompany.value = "Company is mandatory"; haveError = true; } if (mou.isEmpty) { errorMou.value = "Mou is mandatory"; haveError = true; } if (doctor == null) { errorDoctor.value = "Doctor is mandatory"; haveError = true; } if (doctorAddress == null) { errorDoctorAddress.value = "Doctor Address is mandatory"; haveError = true; } if (ctrlLogin.text == "") { errorLogin.value = "Login is mandatory"; haveError = true; } Timer(const Duration(seconds: 3), () { errorCompany.value = null; errorMou.value = null; errorDoctor.value = null; errorDoctorAddress.value = null; errorLogin.value = null; }); return haveError; }; return Dialog( shape: RoundedRectangleBorder( side: const BorderSide(), borderRadius: BorderRadius.circular(10), ), child: SizedBox( width: 800, height: 600, child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(20.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ FxAcCompany( errorValidation: errorCompany.value, ), const SizedBox(height: 10), FxMitraMou( errorValidation: errorMou.value, ), const SizedBox(height: 10), FxAcDoctor( errorValidation: errorDoctor.value, ), const SizedBox(height: 10), FxDoctorAddress( errorValidation: errorDoctorAddress.value, ), const SizedBox(height: 10), FxTextField( ctrl: ctrlLogin, fc: fcLogin, hint: "Login", label: "Login", errorMessage: errorLogin.value, ), const SizedBox(height: 10), FxTextField( ctrl: ctrlPassword, fc: fcPassword, hint: "Password", label: "Password", obscureText: true, errorMessage: errorPassword.value, ), const SizedBox(height: 10), FxTextField( ctrl: ctrlRePassword, fc: fcRePassword, hint: "Retype Password", label: "Retype Password", obscureText: true, errorMessage: errorRePassword.value, ), const SizedBox(height: 10), const FxTextField( hint: "ID", label: "ID", isReadOnly: true, isEnabled: false, suffixText: "Auto Generated", ), const SizedBox(height: 10), Row( mainAxisAlignment: MainAxisAlignment.end, mainAxisSize: MainAxisSize.max, children: [ ElevatedButton( style: ButtonStyle( backgroundColor: MaterialStateColor.resolveWith( (st) => Colors.green, ), ), onPressed: () { if (!validationError()) { ref.read(mitraAddProvider.notifier).add( companyID: company!.mCompanyID, mouID: mou.map((e) => e.mMouID).toList(), doctorID: doctor!.mDoctorID, doctorAddressID: doctorAddress!.mDoctorAddressID, login: ctrlLogin.text, password: ctrlPassword.text, query: "", ); Navigator.of(context).pop(); } }, child: const Text("Save"), ), const SizedBox(width: 20), ElevatedButton( style: ButtonStyle( backgroundColor: MaterialStateColor.resolveWith( (st) => Colors.red, ), ), onPressed: () { Navigator.of(context).pop(); }, child: const Text("Cancel"), ), ], ), ], ), ), )), ); } }