One UI in flutter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

202 lines
7.1 KiB

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/mitra_edit_provider.dart';
import 'provider/selectedCompanyProvider.dart';
import 'provider/selectedDoctorProvider.dart';
class FxMitraEditDialog extends HookConsumerWidget {
final String login;
final String idNo;
final String mitraID;
const FxMitraEditDialog({
Key? key,
required this.login,
required this.idNo,
required this.mitraID,
}) : 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<String?>(null);
final errorDoctor = useState<String?>(null);
final errorDoctorAddress = useState<String?>(null);
final errorMou = useState<String?>(null);
final errorLogin = useState<String?>(null);
final fcPassword = FocusNode();
final fcRePassword = FocusNode();
final errorPassword = useState<String?>(null);
final errorRePassword = useState<String?>(null);
final ctrlLogin = useTextEditingController(text: login);
final ctrlPassword = useTextEditingController(text: "");
final ctrlRePassword = useTextEditingController(text: "");
bool Function() validationError;
validationError = () {
bool haveError = false;
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(
readOnly: true,
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),
FxTextField(
ctrl: useTextEditingController(text: idNo),
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(mitraEditProvider.notifier).edit(
mitraID: mitraID,
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"),
),
],
),
],
),
),
)),
);
}
}