337 lines
16 KiB
Dart
337 lines
16 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:lamiter/Class/Form/constitution_form.dart';
|
|
import 'package:lamiter/Class/Form/health_index_form.dart';
|
|
import 'package:lamiter/Class/Form/physical_index_form.dart';
|
|
import 'package:lamiter/Class/Form/posture_issue_form.dart';
|
|
import 'package:lamiter/Class/Form/sleep_well_index_form.dart';
|
|
import 'package:lamiter/Class/Form/stress_index_form.dart';
|
|
import 'package:lamiter/Class/Form/urban_disease_form.dart';
|
|
import 'package:lamiter/Class/Form/zong_fu_index_form.dart';
|
|
import 'package:lamiter/Component/AppBar/title_app_bar.dart';
|
|
import 'package:lamiter/Component/Button/submit_button.dart';
|
|
import 'package:lamiter/Component/CupertinoForm/cupertino_form_row.dart';
|
|
import 'package:lamiter/Component/CupertinoForm/cupertino_form_section.dart';
|
|
import 'package:lamiter/Extension/build_context.dart';
|
|
import 'package:lamiter/Extension/iterable.dart';
|
|
import 'package:lamiter/Page/Diagnosis/diagnosis_form_page.dart';
|
|
import 'package:lamiter/Page/Diagnosis/diagnosis_report_page.dart';
|
|
import 'package:lamiter/Provider/Diagnosis/diagnosis_provider.dart';
|
|
import 'package:lamiter/Provider/Form/constitution_form_provider.dart';
|
|
import 'package:lamiter/Provider/Form/health_index_form_provider.dart';
|
|
import 'package:lamiter/Provider/Form/physical_index_form_provider.dart';
|
|
import 'package:lamiter/Provider/Form/posture_issue_form_provider.dart';
|
|
import 'package:lamiter/Provider/Form/sleep_well_index_form_provider.dart';
|
|
import 'package:lamiter/Provider/Form/stress_index_form_provider.dart';
|
|
import 'package:lamiter/Provider/Form/urban_disease_form_provider.dart';
|
|
import 'package:lamiter/Provider/Form/zong_fu_index_form_provider.dart';
|
|
import 'package:lamiter/Provider/User/Client/client_calendar_provider.dart';
|
|
import 'package:lamiter/Provider/User/Client/client_provider.dart';
|
|
import 'package:lamiter/Provider/User/manager_provider.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
class DiagnosisPage extends StatefulWidget {
|
|
const DiagnosisPage({super.key});
|
|
|
|
@override
|
|
State<DiagnosisPage> createState() => _DiagnosisPageState();
|
|
}
|
|
|
|
class _DiagnosisPageState extends State<DiagnosisPage> {
|
|
final GlobalKey<SubmitButtonState> submitButtonKey =
|
|
GlobalKey<SubmitButtonState>();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
context.read<DiagnosisProvider>().start(
|
|
context.read<ManagerProvider>().self!,
|
|
context.read<ClientProvider>().self,
|
|
);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final enabled = context.select<DiagnosisProvider, bool>(
|
|
(provider) => provider.isReadyToSubmit());
|
|
final submitting = context
|
|
.select<DiagnosisProvider, bool>((provider) => provider.submitting);
|
|
|
|
final healthIndexForm = context.select<DiagnosisProvider, HealthIndexForm?>(
|
|
(provider) => provider.healthIndexForm);
|
|
final physicalIndexForm =
|
|
context.select<DiagnosisProvider, PhysicalIndexForm?>(
|
|
(provider) => provider.physicalIndexForm);
|
|
final urbanDiseaseForm =
|
|
context.select<DiagnosisProvider, UrbanDiseaseForm?>(
|
|
(provider) => provider.urbanDiseaseForm);
|
|
final stressIndexForm = context.select<DiagnosisProvider, StressIndexForm?>(
|
|
(provider) => provider.stressIndexForm);
|
|
final sleepWellIndexForm =
|
|
context.select<DiagnosisProvider, SleepWellIndexForm?>(
|
|
(provider) => provider.sleepWellIndexForm);
|
|
final constitutionForm =
|
|
context.select<DiagnosisProvider, ConstitutionForm?>(
|
|
(provider) => provider.constitutionForm);
|
|
final zongFuIndexForm = context.select<DiagnosisProvider, ZongFuIndexForm?>(
|
|
(provider) => provider.zongFuIndexForm);
|
|
final postureIssueForm =
|
|
context.select<DiagnosisProvider, PostureIssueForm?>(
|
|
(provider) => provider.postureIssueForm);
|
|
|
|
return GestureDetector(
|
|
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
|
|
child: Stack(
|
|
alignment: Alignment.bottomCenter,
|
|
children: [
|
|
Scaffold(
|
|
appBar: TitleAppBar(title: AppLocalizations.of(context).diagnosis),
|
|
body: SafeArea(
|
|
bottom: false,
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
ListView(
|
|
children: [
|
|
MyCupertinoFormSection(
|
|
title: AppLocalizations.of(context).basic_health,
|
|
items: [
|
|
MyCupertinoFormRow(
|
|
title:
|
|
AppLocalizations.of(context).health_index_form,
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => DiagnosisFormPage<
|
|
HealthIndexFormProvider>(
|
|
title: AppLocalizations.of(context)
|
|
.health_index_form,
|
|
infoText: AppLocalizations.of(context)
|
|
.health_index_form_info,
|
|
prevForm: healthIndexForm,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
completed: healthIndexForm != null,
|
|
),
|
|
MyCupertinoFormRow(
|
|
title: AppLocalizations.of(context)
|
|
.physical_index_form,
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => DiagnosisFormPage<
|
|
PhysicalIndexFormProvider>(
|
|
title: AppLocalizations.of(context)
|
|
.physical_index_form,
|
|
infoText: AppLocalizations.of(context)
|
|
.physical_index_form_info,
|
|
prevForm: physicalIndexForm,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
completed: physicalIndexForm != null,
|
|
),
|
|
MyCupertinoFormRow(
|
|
title:
|
|
AppLocalizations.of(context).urban_disease_form,
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => DiagnosisFormPage<
|
|
UrbanDiseaseFormProvider>(
|
|
title: AppLocalizations.of(context)
|
|
.urban_disease_form,
|
|
infoText: AppLocalizations.of(context)
|
|
.urban_disease_form_info,
|
|
prevForm: urbanDiseaseForm,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
completed: urbanDiseaseForm != null,
|
|
),
|
|
MyCupertinoFormRow(
|
|
title:
|
|
AppLocalizations.of(context).stress_index_form,
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => DiagnosisFormPage<
|
|
StressIndexFormProvider>(
|
|
title: AppLocalizations.of(context)
|
|
.stress_index_form,
|
|
infoText: AppLocalizations.of(context)
|
|
.sleep_well_index_form_info,
|
|
prevForm: stressIndexForm,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
completed: stressIndexForm != null,
|
|
),
|
|
MyCupertinoFormRow(
|
|
title: AppLocalizations.of(context)
|
|
.sleep_well_index_form,
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => DiagnosisFormPage<
|
|
SleepWellIndexFormProvider>(
|
|
title: AppLocalizations.of(context)
|
|
.sleep_well_index_form,
|
|
infoText: AppLocalizations.of(context)
|
|
.sleep_well_index_form_info,
|
|
prevForm: sleepWellIndexForm,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
completed: sleepWellIndexForm != null,
|
|
),
|
|
],
|
|
note: AppLocalizations.of(context).basic_health_footer,
|
|
),
|
|
MyCupertinoFormSection(
|
|
title: AppLocalizations.of(context).constitution,
|
|
items: [
|
|
MyCupertinoFormRow(
|
|
title:
|
|
AppLocalizations.of(context).constitution_model,
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => DiagnosisFormPage<
|
|
ConstitutionFormProvider>(
|
|
title: AppLocalizations.of(context)
|
|
.constitution_model,
|
|
infoText: AppLocalizations.of(context)
|
|
.constitution_model_info,
|
|
prevForm: constitutionForm,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
completed: constitutionForm != null,
|
|
),
|
|
constitutionForm != null
|
|
? MyCupertinoFormRow(
|
|
title: AppLocalizations.of(context)
|
|
.zong_fu_index_form,
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => DiagnosisFormPage<
|
|
ZongFuIndexFormProvider>(
|
|
title: AppLocalizations.of(context)
|
|
.zong_fu_index_form,
|
|
infoText: AppLocalizations.of(context)
|
|
.zong_fu_index_form_info,
|
|
prevForm: zongFuIndexForm,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
completed: zongFuIndexForm != null,
|
|
)
|
|
: MyCupertinoFormRow(
|
|
title: AppLocalizations.of(context)
|
|
.zong_fu_index_form,
|
|
customWidget: Text(
|
|
AppLocalizations.of(context)
|
|
.zong_fu_index_form_not_ready,
|
|
style: TextStyle(
|
|
fontFamily: 'CupertinoSystemText',
|
|
inherit: false,
|
|
fontSize: 13.0,
|
|
fontWeight: FontWeight.w400,
|
|
textBaseline: TextBaseline.alphabetic,
|
|
color: context.inversePrimary
|
|
.withOpacity(0.5),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
note: AppLocalizations.of(context).constitution_footer,
|
|
),
|
|
MyCupertinoFormSection(
|
|
title: AppLocalizations.of(context).posture_issue,
|
|
items: [
|
|
MyCupertinoFormRow(
|
|
title: AppLocalizations.of(context)
|
|
.posture_issue_model,
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => DiagnosisFormPage<
|
|
PostureIssueFormProvider>(
|
|
title: AppLocalizations.of(context)
|
|
.posture_issue_model,
|
|
infoText: AppLocalizations.of(context)
|
|
.posture_issue_model_info,
|
|
prevForm: postureIssueForm,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
completed: postureIssueForm != null,
|
|
),
|
|
],
|
|
note: AppLocalizations.of(context).posture_issue_footer,
|
|
),
|
|
]
|
|
.lastPadding(
|
|
EdgeInsets.only(bottom: context.height(0.1)))
|
|
.toList(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
SubmitButton(
|
|
key: submitButtonKey,
|
|
text: AppLocalizations.of(context).diagnosis_report,
|
|
enabled: enabled,
|
|
submitting: submitting,
|
|
onTap: () async {
|
|
Map<String, dynamic> response =
|
|
await context.read<DiagnosisProvider>().submit();
|
|
if (response.containsKey("success")) {
|
|
final diagnosis = context.read<DiagnosisProvider>().diagnosis!;
|
|
await context.read<ClientCalendarProvider>().refresh();
|
|
Navigator.pushReplacement(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) =>
|
|
DiagnosisReportPage(diagnosis: diagnosis),
|
|
),
|
|
);
|
|
}
|
|
if (response.containsKey("errorMessage")) {
|
|
submitButtonKey.currentState?.showMessage(
|
|
response['errorMessage'],
|
|
context.error,
|
|
);
|
|
return;
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|