This commit is contained in:
zhutao
2025-09-01 16:24:34 +08:00
parent b110d1439c
commit bdfd051a47
8 changed files with 284 additions and 241 deletions

View File

@@ -1,12 +1,9 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:food_health/api/dto/user_profile_dto.dart';
import 'package:food_health/api/endpoints/profile_api.dart';
import 'package:food_health/config/theme/custom_colors.dart';
import 'package:go_router/go_router.dart';
import 'package:food_health/providers/user_store.dart';
import 'package:provider/provider.dart';
import 'package:remixicon/remixicon.dart';
import '../../../router/config/route_paths.dart';
import 'widget/title_card.dart';
import 'widget/user_card.dart';
@@ -18,56 +15,6 @@ class MyPage extends StatefulWidget {
}
class _MyPageState extends State<MyPage> with AutomaticKeepAliveClientMixin {
UserProfileDto _userProfile = UserProfileDto();
@override
void initState() {
super.initState();
_init();
}
void _init() async {
var res = await getUserProfileApi();
setState(() {
_userProfile = res;
});
_showEditProfile();
}
void _goEdit() async {
var isUpload = await context.push(RoutePaths.myEdit, extra: _userProfile);
if (isUpload == true) {
_init();
}
}
void _showEditProfile() {
if (_userProfile.qStatus != 1) {
showCupertinoDialog(
context: context,
builder: (_) => CupertinoAlertDialog(
title: Text("Complete Your Profile"),
content: Text("Lets get to know you better! Please take a quick survey to personalize your experience."),
actions: [
CupertinoDialogAction(
child: Text("Not Now"),
onPressed: () {
context.pop();
},
),
CupertinoDialogAction(
child: Text("Take Survey"),
onPressed: () {
context.pop();
_goEdit();
},
),
],
),
);
}
}
@override
Widget build(BuildContext context) {
super.build(context);
@@ -75,70 +22,92 @@ class _MyPageState extends State<MyPage> with AutomaticKeepAliveClientMixin {
child: ListView(
padding: EdgeInsets.all(15),
children: [
UserCard(
detail: _userProfile,
onEdit: _goEdit,
),
Column(
children: [
TitleCard(
title: "Food Allergies",
icon: Icon(
RemixIcons.shield_line,
color: Theme.of(context).colorScheme.danger,
),
child: buildTagList(
emptyText: "No allergies reported",
tags: _userProfile.foodAllergiesList,
color: Theme.of(context).colorScheme.danger,
),
),
TitleCard(
title: "No preferences",
icon: Icon(
RemixIcons.heart_line,
color: Theme.of(context).colorScheme.success,
),
child: buildTagList(
emptyText: "No dietary preferences reported",
tags: _userProfile.dietaryPreferencesList,
color: Theme.of(context).colorScheme.success,
),
),
TitleCard(
title: "Medical Information",
icon: Icon(
RemixIcons.user_line,
color: Theme.of(context).colorScheme.primary,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
UserCard(),
Consumer<UserStore>(
builder: (context, store, _) {
return Column(
children: [
Container(
margin: EdgeInsets.only(bottom: 10),
child: Text("Medical Conditions"),
),
Container(
margin: EdgeInsets.only(bottom: 10),
TitleCard(
title: "Food Allergies",
icon: Icon(
RemixIcons.shield_line,
color: Theme
.of(context)
.colorScheme
.danger,
),
child: buildTagList(
emptyText: "No medical conditions reported",
tags: _userProfile.medicalInformationList,
color: Theme.of(context).colorScheme.primary,
emptyText: "No allergies reported",
tags: store.profile.foodAllergiesList,
color: Theme
.of(context)
.colorScheme
.danger,
),
),
Container(
margin: EdgeInsets.only(bottom: 10),
child: Text("Current Medications"),
TitleCard(
title: "No preferences",
icon: Icon(
RemixIcons.heart_line,
color: Theme
.of(context)
.colorScheme
.success,
),
child: buildTagList(
emptyText: "No dietary preferences reported",
tags: store.profile.dietaryPreferencesList,
color: Theme
.of(context)
.colorScheme
.success,
),
),
buildTagList(
emptyText: "No medications reported",
tags: _userProfile.currentMedicationsList,
color: Theme.of(context).colorScheme.primary,
TitleCard(
title: "Medical Information",
icon: Icon(
RemixIcons.user_line,
color: Theme
.of(context)
.colorScheme
.primary,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(bottom: 10),
child: Text("Medical Conditions"),
),
Container(
margin: EdgeInsets.only(bottom: 10),
child: buildTagList(
emptyText: "No medical conditions reported",
tags: store.profile.medicalInformationList,
color: Theme
.of(context)
.colorScheme
.primary,
),
),
Container(
margin: EdgeInsets.only(bottom: 10),
child: Text("Current Medications"),
),
buildTagList(
emptyText: "No medications reported",
tags: store.profile.currentMedicationsList,
color: Theme
.of(context)
.colorScheme
.primary,
),
],
),
),
],
),
),
],
);
}
),
],
),