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.
 
 
 
 
 
 

156 lines
5.5 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/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<String?>(null);
final errorDoctor = useState<String?>(null);
final errorDoctorAddress = useState<String?>(null);
final errorMou = useState<String?>(null);
final errorLogin = useState<String?>(null);
final ctrlLogin = useTextEditingController(text: "");
bool Function() validationError;
validationError = () {
bool haveError = false;
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),
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,
);
}
},
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"),
),
],
),
],
),
),
)),
);
}
}