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.
112 lines
4.2 KiB
112 lines
4.2 KiB
import 'package:flutter/material.dart'; |
|
import 'package:flutter_hooks/flutter_hooks.dart'; |
|
import 'package:hooks_riverpod/hooks_riverpod.dart'; |
|
import 'package:onemd/model/ac_doctor_model.dart'; |
|
|
|
import 'fx_data_mitra.dart'; |
|
import 'fx_error_text.dart'; |
|
import 'provider/doctor_address_lookup_provider.dart'; |
|
import 'provider/selectedDoctorProvider.dart'; |
|
|
|
class FxDoctorAddress extends HookConsumerWidget { |
|
final double? width; |
|
final String? errorValidation; |
|
bool isInit; |
|
FxDoctorAddress({ |
|
Key? key, |
|
this.width, |
|
this.errorValidation, |
|
this.isInit = true, |
|
}) : super(key: key); |
|
|
|
@override |
|
Widget build(BuildContext context, WidgetRef ref) { |
|
final listAddress = |
|
useState<List<AcDoctorAddressResponseModel>>(List.empty()); |
|
|
|
final doctorModel = ref.watch(selectedAcDoctorProvider); |
|
String doctorName = doctorModel?.fullName ?? ""; |
|
final initState = useState(isInit); |
|
|
|
ref.listen(doctorAddressLookupProvider, (prev, next) { |
|
if (next is DoctorAddressLookupStateDone) { |
|
for (int idx = 0; idx < next.list.length; idx++) { |
|
if (ref.read(selectedAcDoctorAddressProvider)?.mDoctorAddressID != |
|
null && |
|
ref.read(selectedAcDoctorAddressProvider)!.mDoctorAddressID == |
|
next.list[idx].mDoctorAddressID) { |
|
ref.read(selectedAcDoctorAddressProvider.notifier).state = |
|
next.list[idx]; |
|
} |
|
} |
|
listAddress.value = next.list; |
|
} |
|
}); |
|
return Container( |
|
width: double.infinity, |
|
decoration: BoxDecoration( |
|
borderRadius: BorderRadius.circular(10), |
|
border: Border.all( |
|
color: errorValidation == null |
|
? Colors.blue.shade700 |
|
: Colors.red.shade700, |
|
), |
|
color: Colors.blue.shade100.withOpacity(0.3), |
|
), |
|
child: ConstrainedBox( |
|
constraints: BoxConstraints.loose(const Size(double.infinity, 150)), |
|
child: Padding( |
|
padding: const EdgeInsets.all(8.0), |
|
child: Column( |
|
mainAxisSize: MainAxisSize.min, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
errorValidation == null |
|
? FxNormalBlueText( |
|
title: "Address of $doctorName", |
|
isBold: true, |
|
) |
|
: FxErrorText( |
|
title: "Address of $doctorName *) $errorValidation"), |
|
const SizedBox(height: 10), |
|
if (listAddress.value.isNotEmpty) |
|
ConstrainedBox( |
|
constraints: |
|
BoxConstraints.loose(const Size(double.infinity, 100)), |
|
child: ListView.builder( |
|
shrinkWrap: true, |
|
itemCount: listAddress.value.length, |
|
itemBuilder: (context, idx) { |
|
final model = listAddress.value[idx]; |
|
return Row( |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Radio<AcDoctorAddressResponseModel>( |
|
groupValue: |
|
ref.watch(selectedAcDoctorAddressProvider), |
|
value: model, |
|
onChanged: ((val) { |
|
ref |
|
.read(selectedAcDoctorAddressProvider |
|
.notifier) |
|
.state = val; |
|
}), |
|
), |
|
const SizedBox(width: 10), |
|
Expanded( |
|
child: FxNormalBlueText( |
|
title: model.mDoctorAddressDescription |
|
.replaceAll("\n", ""), |
|
), |
|
), |
|
], |
|
); |
|
}, |
|
), |
|
), |
|
], |
|
), |
|
), |
|
)); |
|
} |
|
}
|
|
|