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,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:food_health/api/dto/profile_options_dto.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:food_health/page/profile/edit/widget/food_allergies.dart';
import 'package:food_health/providers/user_store.dart';
import 'package:food_health/widgets/common/app_backend.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import 'package:remixicon/remixicon.dart';
import 'data/state.dart';
@@ -14,9 +15,7 @@ import 'widget/dietary_preferences.dart';
import 'widget/health_profile.dart';
class MyEditPage extends StatefulWidget {
final UserProfileDto userProfile;
const MyEditPage({super.key, required this.userProfile});
const MyEditPage({super.key});
@override
State<MyEditPage> createState() => _MyEditPageState();
@@ -57,7 +56,8 @@ class _MyEditPageState extends State<MyEditPage> {
}
void _init() async {
selectionState = SelectionState(widget.userProfile);
UserStore userStore = context.read<UserStore>();
selectionState = SelectionState(userStore.profile);
var res = await getProfileOptionsApi();
setState(() {
_options = res;
@@ -91,74 +91,89 @@ class _MyEditPageState extends State<MyEditPage> {
if (_loading) {
return Center(child: CircularProgressIndicator());
}
return Scaffold(
body: AppBackend(
child: ListView(
padding: EdgeInsets.only(top: 30),
children: [
buildHeader(),
buildStep(),
buildStepInfo(),
SelectionProvider(
notifier: selectionState,
child: Builder(
builder: (context) {
if (_step == 0) {
return FoodAllergies(
options: _options,
);
} else if (_step == 1) {
return DietaryPreferences(
options: _options,
);
} else if (_step == 2) {
return HealthProfile(
options: _options,
);
}
return SizedBox();
},
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, __) async {
if (didPop) return;
if (selectionState.userProfile.qStatus == 1) {
context.pop();
}
},
child: Scaffold(
body: AppBackend(
child: Column(
children: [
Expanded(
child: ListView(
padding: EdgeInsets.only(top: 20),
children: [
buildHeader(),
buildStep(),
buildStepInfo(),
SelectionProvider(
notifier: selectionState,
child: Builder(
builder: (context) {
if (_step == 0) {
return FoodAllergies(
options: _options,
);
} else if (_step == 1) {
return DietaryPreferences(
options: _options,
);
} else if (_step == 2) {
return HealthProfile(
options: _options,
);
}
return SizedBox();
},
),
),
],
),
),
),
Container(
margin: EdgeInsets.only(top: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Opacity(
opacity: _step == 0 ? 0.4 : 1,
child: buildItemButton(
title: "Previous",
color: Colors.black,
Container(
margin: EdgeInsets.only(top: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Opacity(
opacity: _step == 0 ? 0.4 : 1,
child: buildItemButton(
title: "Previous",
color: Colors.black,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainer,
),
onTap: () {
_handStep(false);
},
),
),
buildItemButton(
title: _step == 2 ? "Complete Setup" : "Continue",
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainer,
color: _step == 2 ? Theme.of(context).colorScheme.success : null,
gradient: _step == 2
? null
: LinearGradient(
colors: [
Theme.of(context).colorScheme.primary,
Theme.of(context).colorScheme.primaryEnd,
],
),
),
onTap: () {
_handStep(false);
_handStep(true);
},
),
),
buildItemButton(
title: _step == 2 ? "Complete Setup" : "Continue",
decoration: BoxDecoration(
color: _step == 2 ? Theme.of(context).colorScheme.success : null,
gradient: _step == 2
? null
: LinearGradient(
colors: [
Theme.of(context).colorScheme.primary,
Theme.of(context).colorScheme.primaryEnd,
],
),
),
onTap: () {
_handStep(true);
},
),
],
],
),
),
),
],
],
),
),
),
);