switch_patient_dialog.dart 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import 'package:eitc_erm_dental_flutter/entity/db/local_patient_info.dart';
  2. import 'package:eitc_erm_dental_flutter/funcs.dart';
  3. import 'package:eitc_erm_dental_flutter/pages/patient/vm/patient_view_model.dart';
  4. import 'package:eitc_erm_dental_flutter/pages/patient/widget/patient_list_item.dart';
  5. import 'package:eitc_erm_dental_flutter/widget/main_button.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter_riverpod/flutter_riverpod.dart';
  8. import 'package:flutter_screenutil/flutter_screenutil.dart';
  9. ///切换咨询人弹窗
  10. class SwitchPatientDialog extends ConsumerWidget {
  11. final void Function(LocalPatientInfo)? onSelectPatient;
  12. final VoidCallback onAddPatient;
  13. const SwitchPatientDialog(
  14. {super.key, required this.onSelectPatient, required this.onAddPatient});
  15. @override
  16. Widget build(BuildContext context, WidgetRef ref) {
  17. AsyncValue<List<LocalPatientInfo>> value =
  18. ref.watch(localPatientListProvider);
  19. return Container(
  20. width: double.infinity,
  21. padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
  22. decoration: BoxDecoration(
  23. color: Colors.white,
  24. borderRadius: BorderRadius.only(
  25. topLeft: Radius.circular(8.r), topRight: Radius.circular(8.r))),
  26. child: Column(
  27. mainAxisSize: MainAxisSize.min,
  28. children: [
  29. Text(getS().selectPatient),
  30. SizedBox(
  31. height: 10.h,
  32. ),
  33. _getContent(value),
  34. SizedBox(
  35. height: 15.h,
  36. ),
  37. SizedBox(
  38. width: double.infinity,
  39. child: MainButton(text: getS().addPatient, onPressed: onAddPatient),
  40. ),
  41. ],
  42. ),
  43. );
  44. }
  45. Widget _getContent(AsyncValue<List<LocalPatientInfo>> value) {
  46. return switch (value) {
  47. AsyncData(value: var data) => _getList(data),
  48. AsyncError() => _getList([]),
  49. _ => CircularProgressIndicator()
  50. };
  51. }
  52. Widget _getList(List<LocalPatientInfo> list) {
  53. if (list.isEmpty) {
  54. return SizedBox();
  55. }
  56. return ListView.separated(
  57. shrinkWrap: true,
  58. itemBuilder: (ctx, index) {
  59. LocalPatientInfo info = list[index];
  60. return PatientListItem(
  61. index: index,
  62. name: info.name ?? "",
  63. idCard: info.idCardDecrypt,
  64. relation: info.relation ?? getS().unknown,
  65. onTap: (i) => onSelectPatient?.call(list[i]));
  66. },
  67. separatorBuilder: (ctx, index) => SizedBox(
  68. height: 10.h,
  69. ),
  70. itemCount: list.length,
  71. );
  72. }
  73. }