基本完成
This commit is contained in:
30
lib/page/home/home_page.dart
Normal file
30
lib/page/home/home_page.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:food_health/page/home/widget/home_header.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../widgets/common/app_backend.dart';
|
||||
import '../../widgets/common/app_header.dart';
|
||||
import 'widget/upload_panel.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
|
||||
@override
|
||||
State<HomePage> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: AppBackend(
|
||||
child: ListView(
|
||||
children: [AppHeader(), HomeHeader(), UploadPanel()],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
28
lib/page/home/widget/home_header.dart
Normal file
28
lib/page/home/widget/home_header.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class HomeHeader extends StatelessWidget {
|
||||
const HomeHeader({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: 30, bottom: 40),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
"Food Safety Scanner",
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 10),
|
||||
child: Text(
|
||||
"Upload a photo to check if this food is safe for you",
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
193
lib/page/home/widget/upload_panel.dart
Normal file
193
lib/page/home/widget/upload_panel.dart
Normal file
@@ -0,0 +1,193 @@
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||
import 'package:food_health/api/endpoints/food_api.dart';
|
||||
import 'package:food_health/config/theme/custom_colors.dart';
|
||||
import 'package:food_health/router/config/route_paths.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
class UploadPanel extends StatefulWidget {
|
||||
const UploadPanel({super.key});
|
||||
|
||||
@override
|
||||
State<UploadPanel> createState() => _UploadPanelState();
|
||||
}
|
||||
|
||||
class _UploadPanelState extends State<UploadPanel> {
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
|
||||
///打开相机拍照
|
||||
void _handTakePhoto() async {
|
||||
var photo = await _picker.pickImage(source: ImageSource.camera);
|
||||
if (photo != null) {
|
||||
_startDetect(photo.path);
|
||||
}
|
||||
}
|
||||
|
||||
///选择图片
|
||||
void _handPickImage() async {
|
||||
var result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.image,
|
||||
allowMultiple: false,
|
||||
);
|
||||
if (result != null) {
|
||||
_startDetect(result.files[0].path!);
|
||||
}
|
||||
}
|
||||
|
||||
///开始检测
|
||||
void _startDetect(String path) async {
|
||||
//压缩
|
||||
final result = await FlutterImageCompress.compressWithFile(
|
||||
path,
|
||||
minWidth: 1080,
|
||||
minHeight: 1920,
|
||||
quality: 85,
|
||||
rotate: 0,
|
||||
);
|
||||
EasyLoading.show(
|
||||
status: 'Checking, please wait...',
|
||||
maskType: EasyLoadingMaskType.clear,
|
||||
);
|
||||
var res = await foodScanApi(result!);
|
||||
EasyLoading.dismiss();
|
||||
context.push(RoutePaths.detail, extra: res);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color(0x1A000000),
|
||||
spreadRadius: 2,
|
||||
blurRadius: 5,
|
||||
offset: Offset(1, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(30),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 70,
|
||||
height: 70,
|
||||
margin: EdgeInsets.only(bottom: 20),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
Theme.of(context).colorScheme.primary,
|
||||
Theme.of(context).colorScheme.primaryEnd,
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
RemixIcons.image_line,
|
||||
color: Colors.white,
|
||||
size: 26,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
"Upload Food Photo",
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 5),
|
||||
child: Text(
|
||||
"Take a clear photo of your food and we'll analyze it for safety based on your health profile",
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 40, bottom: 20),
|
||||
child: Column(
|
||||
spacing: 20,
|
||||
children: [
|
||||
_buttonItem(
|
||||
title: "Take Photo",
|
||||
icon: RemixIcons.camera_line,
|
||||
style: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
Theme.of(context).colorScheme.primary,
|
||||
Theme.of(context).colorScheme.primaryEnd,
|
||||
],
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
_handTakePhoto();
|
||||
},
|
||||
),
|
||||
_buttonItem(
|
||||
title: "Upload File",
|
||||
icon: RemixIcons.upload_2_line,
|
||||
color: Colors.black,
|
||||
style: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
),
|
||||
onTap: () {
|
||||
_handPickImage();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
"Supports JPG, PNG, HEIC formats • Max 10MB",
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buttonItem({
|
||||
required String title,
|
||||
required IconData icon,
|
||||
Color color = Colors.white,
|
||||
required BoxDecoration style,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: 170,
|
||||
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 15),
|
||||
decoration: style.copyWith(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 10,
|
||||
children: [
|
||||
Icon(icon, color: color, size: 20),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(color: color),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
25
lib/page/profile/edit/data/state.dart
Normal file
25
lib/page/profile/edit/data/state.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/api/dto/user_profile_dto.dart';
|
||||
|
||||
class SelectionState extends ChangeNotifier {
|
||||
UserProfileDto userProfile = UserProfileDto();
|
||||
|
||||
SelectionState(this.userProfile);
|
||||
|
||||
void update(void Function(UserProfileDto) updater) {
|
||||
updater(userProfile);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
class SelectionProvider extends InheritedNotifier<SelectionState> {
|
||||
const SelectionProvider({
|
||||
super.key,
|
||||
required SelectionState super.notifier,
|
||||
required super.child,
|
||||
});
|
||||
|
||||
static SelectionState of(BuildContext context) {
|
||||
return context.dependOnInheritedWidgetOfExactType<SelectionProvider>()!.notifier!;
|
||||
}
|
||||
}
|
||||
292
lib/page/profile/edit/my_edit_page.dart
Normal file
292
lib/page/profile/edit/my_edit_page.dart
Normal file
@@ -0,0 +1,292 @@
|
||||
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/widgets/common/app_backend.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import 'data/state.dart';
|
||||
import 'widget/dietary_preferences.dart';
|
||||
import 'widget/health_profile.dart';
|
||||
|
||||
class MyEditPage extends StatefulWidget {
|
||||
final UserProfileDto userProfile;
|
||||
|
||||
const MyEditPage({super.key, required this.userProfile});
|
||||
|
||||
@override
|
||||
State<MyEditPage> createState() => _MyEditPageState();
|
||||
}
|
||||
|
||||
class _MyEditPageState extends State<MyEditPage> {
|
||||
late SelectionState selectionState;
|
||||
|
||||
List<ProfileOptionDto> _options = [];
|
||||
|
||||
var _loading = true;
|
||||
|
||||
///步骤
|
||||
var _step = 0;
|
||||
|
||||
var stepList = [
|
||||
StepItem(
|
||||
title: "Food Allergies",
|
||||
icon: RemixIcons.shield_line,
|
||||
subTitle: "Help us keep you safe by telling us about your allergies",
|
||||
),
|
||||
StepItem(
|
||||
title: "Dietary Preferences",
|
||||
icon: RemixIcons.heart_line,
|
||||
subTitle: "What dietary restrictions or preferences do you follow?",
|
||||
),
|
||||
StepItem(
|
||||
title: "Health Profile",
|
||||
icon: RemixIcons.user_line,
|
||||
subTitle: "Share relevant health information for personalized recommendations",
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_init();
|
||||
}
|
||||
|
||||
void _init() async {
|
||||
selectionState = SelectionState(widget.userProfile);
|
||||
var res = await getProfileOptionsApi();
|
||||
setState(() {
|
||||
_options = res;
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
///设置步骤
|
||||
void _handStep(bool isNext) {
|
||||
if (_step == 2 && isNext) {
|
||||
_submit();
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_step = (_step + (isNext ? 1 : -1)).clamp(0, 2);
|
||||
});
|
||||
}
|
||||
|
||||
void _submit() async {
|
||||
EasyLoading.show(
|
||||
status: 'Saving…',
|
||||
maskType: EasyLoadingMaskType.clear,
|
||||
);
|
||||
await updateProfileApi(selectionState.userProfile);
|
||||
EasyLoading.dismiss();
|
||||
context.pop();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
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();
|
||||
},
|
||||
),
|
||||
),
|
||||
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,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
),
|
||||
onTap: () {
|
||||
_handStep(false);
|
||||
},
|
||||
),
|
||||
),
|
||||
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);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///构建顶部
|
||||
Widget buildHeader() {
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
"Welcome to FoodSafe",
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 5),
|
||||
child: Text(
|
||||
"Let's personalize your food safety experience",
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
///步骤条
|
||||
Widget buildStep() {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: 20),
|
||||
child: Row(
|
||||
spacing: 10,
|
||||
children: stepList.asMap().entries.map((entre) {
|
||||
//数据
|
||||
var item = entre.value;
|
||||
var index = entre.key;
|
||||
var isLast = index == stepList.length - 1;
|
||||
//颜色
|
||||
var selectColor = Theme.of(context).colorScheme.primary;
|
||||
var unselectedColor = Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
return Expanded(
|
||||
flex: isLast ? 0 : 1,
|
||||
child: Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: _step >= index ? selectColor : unselectedColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
item.icon,
|
||||
color: _step >= index ? Colors.white : Color(0xff9ca3af),
|
||||
),
|
||||
),
|
||||
|
||||
Visibility(
|
||||
visible: !isLast,
|
||||
child: Expanded(
|
||||
child: Container(
|
||||
height: 3,
|
||||
color: _step > index ? selectColor : unselectedColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///步骤条信息
|
||||
Widget buildStepInfo() {
|
||||
var stepInfo = stepList[_step];
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: 20, bottom: 30),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
stepInfo.title,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 5),
|
||||
child: Text(
|
||||
stepInfo.subTitle,
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///item按钮
|
||||
Widget buildItemButton({
|
||||
required String title,
|
||||
Color color = Colors.white,
|
||||
required BoxDecoration decoration,
|
||||
required Function() onTap,
|
||||
}) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
|
||||
decoration: decoration.copyWith(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
title,
|
||||
style: TextStyle(color: color),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class StepItem {
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String subTitle;
|
||||
|
||||
StepItem({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.subTitle,
|
||||
});
|
||||
}
|
||||
9
lib/page/profile/edit/util/common.dart
Normal file
9
lib/page/profile/edit/util/common.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
import 'package:food_health/api/dto/profile_options_dto.dart';
|
||||
|
||||
List<String> getOptions(List<ProfileOptionDto> options, String key) {
|
||||
var data = options.firstWhere((item) {
|
||||
return item.key == key;
|
||||
});
|
||||
//
|
||||
return data.valuesList ?? [];
|
||||
}
|
||||
100
lib/page/profile/edit/widget/common.dart
Normal file
100
lib/page/profile/edit/widget/common.dart
Normal file
@@ -0,0 +1,100 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
///步骤内容卡片
|
||||
class StepContentCard extends StatelessWidget {
|
||||
final List<Widget> children;
|
||||
|
||||
const StepContentCard({super.key, required this.children});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Theme.of(context).colorScheme.shadow,
|
||||
blurRadius: 7,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: children,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
///卡片标题
|
||||
class CardTitle extends StatelessWidget {
|
||||
final String title;
|
||||
|
||||
const CardTitle({super.key, required this.title});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 15),
|
||||
child: Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
///配置列表
|
||||
class OptionList extends StatelessWidget {
|
||||
final List<String> options;
|
||||
final List<String> selects;
|
||||
final double widthFactor;
|
||||
final Function(String) onTap;
|
||||
|
||||
const OptionList({
|
||||
super.key,
|
||||
required this.options,
|
||||
required this.selects,
|
||||
this.widthFactor = 0.5,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Wrap(
|
||||
runSpacing: 20,
|
||||
children: options.map((item) {
|
||||
return FractionallySizedBox(
|
||||
widthFactor: widthFactor,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
onTap(item);
|
||||
},
|
||||
child: Row(
|
||||
spacing: 5,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: Checkbox(
|
||||
value: selects.contains(item),
|
||||
onChanged: (_) {
|
||||
onTap(item);
|
||||
},
|
||||
),
|
||||
),
|
||||
Text(item),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
127
lib/page/profile/edit/widget/dietary_preferences.dart
Normal file
127
lib/page/profile/edit/widget/dietary_preferences.dart
Normal file
@@ -0,0 +1,127 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/api/dto/profile_options_dto.dart';
|
||||
|
||||
import '../data/state.dart';
|
||||
import '../util/common.dart';
|
||||
import 'common.dart';
|
||||
|
||||
class DietaryPreferences extends StatefulWidget {
|
||||
final List<ProfileOptionDto> options;
|
||||
|
||||
const DietaryPreferences({super.key, required this.options});
|
||||
|
||||
@override
|
||||
State<DietaryPreferences> createState() => _DietaryPreferencesState();
|
||||
}
|
||||
|
||||
class _DietaryPreferencesState extends State<DietaryPreferences> {
|
||||
///切换标签
|
||||
void _handToggle(String tag) {
|
||||
var state = SelectionProvider.of(context);
|
||||
if (getIsSelect(tag)) {
|
||||
state.update((p) => p.dietaryPreferencesList.remove(tag));
|
||||
} else {
|
||||
state.update((p) => p.dietaryPreferencesList.add(tag));
|
||||
}
|
||||
}
|
||||
|
||||
///选中年龄
|
||||
void _handAgeRange(String tag) {
|
||||
var state = SelectionProvider.of(context);
|
||||
state.update((p) => p.ageRange = tag);
|
||||
}
|
||||
|
||||
///等级
|
||||
void _handActivityLevel(String tag) {
|
||||
var state = SelectionProvider.of(context);
|
||||
state.update((p) => p.activityLevel = tag);
|
||||
}
|
||||
|
||||
///是否标签选中
|
||||
bool getIsSelect(String tag) {
|
||||
var state = SelectionProvider.of(context);
|
||||
return state.userProfile.dietaryPreferencesList.contains(tag);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var state = SelectionProvider.of(context);
|
||||
return StepContentCard(
|
||||
children: [
|
||||
CardTitle(title: "Dietary Restrictions & Preferences"),
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 15),
|
||||
child: OptionList(
|
||||
options: getOptions(widget.options, "dietary_restrictions"),
|
||||
selects: state.userProfile.dietaryPreferencesList,
|
||||
onTap: _handToggle,
|
||||
),
|
||||
),
|
||||
CardTitle(title: "Age Range"),
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 15),
|
||||
child: RadioGroup(
|
||||
options: getOptions(widget.options, "age_ranges"),
|
||||
value: state.userProfile.ageRange,
|
||||
onChanged: _handAgeRange,
|
||||
),
|
||||
),
|
||||
CardTitle(title: "Activity Level"),
|
||||
RadioGroup(
|
||||
options: getOptions(widget.options, "activity_levels"),
|
||||
value: state.userProfile.activityLevel,
|
||||
onChanged: _handActivityLevel,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
///单选列表
|
||||
class RadioGroup extends StatelessWidget {
|
||||
final List<String> options;
|
||||
final String value;
|
||||
final int crossAxisCount;
|
||||
final Function(String) onChanged;
|
||||
|
||||
const RadioGroup({
|
||||
super.key,
|
||||
required this.options,
|
||||
required this.value,
|
||||
this.crossAxisCount = 3,
|
||||
required this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisSpacing: 10,
|
||||
mainAxisSpacing: 10,
|
||||
crossAxisCount: crossAxisCount,
|
||||
mainAxisExtent: 40,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
var data = options[index];
|
||||
var isSelected = value == data;
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
onChanged(data);
|
||||
},
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.surfaceContainerLow,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: isSelected ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.surfaceContainer),
|
||||
),
|
||||
child: Text(data, style: TextStyle(color: isSelected ? Colors.white : Colors.black)),
|
||||
),
|
||||
);
|
||||
},
|
||||
itemCount: options.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
144
lib/page/profile/edit/widget/food_allergies.dart
Normal file
144
lib/page/profile/edit/widget/food_allergies.dart
Normal file
@@ -0,0 +1,144 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/api/dto/profile_options_dto.dart';
|
||||
import 'package:food_health/config/theme/custom_colors.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import '../data/state.dart';
|
||||
import '../util/common.dart';
|
||||
import 'common.dart';
|
||||
|
||||
class FoodAllergies extends StatefulWidget {
|
||||
final List<ProfileOptionDto> options;
|
||||
|
||||
const FoodAllergies({super.key, required this.options});
|
||||
|
||||
@override
|
||||
State<FoodAllergies> createState() => _FoodAllergiesState();
|
||||
}
|
||||
|
||||
class _FoodAllergiesState extends State<FoodAllergies> {
|
||||
final TextEditingController _otherController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
///切换标签
|
||||
void _handToggle(String tag) {
|
||||
var state = SelectionProvider.of(context);
|
||||
if (getIsSelect(tag)) {
|
||||
state.update((p) => p.foodAllergiesList.remove(tag));
|
||||
} else {
|
||||
state.update((p) => p.foodAllergiesList.add(tag));
|
||||
}
|
||||
}
|
||||
|
||||
void _handConfirmCustom() {
|
||||
var state = SelectionProvider.of(context);
|
||||
if (!getIsSelect(_otherController.text)) {
|
||||
state.update((p) => p.foodAllergiesList.add(_otherController.text));
|
||||
_otherController.text = "";
|
||||
}
|
||||
}
|
||||
|
||||
///是否标签选中
|
||||
bool getIsSelect(String tag) {
|
||||
var state = SelectionProvider.of(context);
|
||||
return state.userProfile.foodAllergiesList.contains(tag);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var state = SelectionProvider.of(context);
|
||||
return StepContentCard(
|
||||
children: [
|
||||
CardTitle(title: "Common Food Allergies"),
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 15),
|
||||
child: OptionList(
|
||||
options: getOptions(widget.options, "common_food_allergies"),
|
||||
selects: state.userProfile.foodAllergiesList,
|
||||
onTap: _handToggle,
|
||||
),
|
||||
),
|
||||
CardTitle(title: "Other Allergies"),
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 15),
|
||||
child: Row(
|
||||
spacing: 15,
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _otherController,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
decoration: InputDecoration(
|
||||
isCollapsed: true,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
||||
hintText: "Add custom allergy...",
|
||||
filled: true,
|
||||
fillColor: Theme.of(context).colorScheme.surfaceContainerLow,
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: BorderSide(width: 1, color: Theme.of(context).colorScheme.surfaceContainer),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: BorderSide(width: 1, color: Theme.of(context).colorScheme.surfaceContainer),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: _handConfirmCustom,
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(RemixIcons.add_fill),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
CardTitle(title: "Your Allergies"),
|
||||
Wrap(
|
||||
runSpacing: 10,
|
||||
spacing: 10,
|
||||
children: state.userProfile.foodAllergiesList.map((item) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
_handToggle(item);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 3, horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.danger,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
spacing: 5,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
item,
|
||||
style: TextStyle(color: Colors.white, fontSize: 12),
|
||||
),
|
||||
Icon(
|
||||
RemixIcons.close_fill,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
151
lib/page/profile/edit/widget/health_profile.dart
Normal file
151
lib/page/profile/edit/widget/health_profile.dart
Normal file
@@ -0,0 +1,151 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/api/dto/profile_options_dto.dart';
|
||||
import 'package:food_health/config/theme/custom_colors.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import '../data/state.dart';
|
||||
import '../util/common.dart';
|
||||
import 'common.dart';
|
||||
|
||||
class HealthProfile extends StatefulWidget {
|
||||
final List<ProfileOptionDto> options;
|
||||
|
||||
const HealthProfile({super.key, required this.options});
|
||||
|
||||
@override
|
||||
State<HealthProfile> createState() => _HealthProfileState();
|
||||
}
|
||||
|
||||
class _HealthProfileState extends State<HealthProfile> {
|
||||
final TextEditingController _otherController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
///切换标签
|
||||
void _handToggle(String tag) {
|
||||
var state = SelectionProvider.of(context);
|
||||
if (getIsSelect(tag)) {
|
||||
state.update((p) => p.medicalInformationList.remove(tag));
|
||||
} else {
|
||||
state.update((p) => p.medicalInformationList.add(tag));
|
||||
}
|
||||
}
|
||||
|
||||
///确认搜索内容
|
||||
void _handConfirmCustom() {
|
||||
var state = SelectionProvider.of(context);
|
||||
if (!getIsSelect(_otherController.text)) {
|
||||
state.update((p) => p.currentMedicationsList.add(_otherController.text));
|
||||
_otherController.text = "";
|
||||
}
|
||||
}
|
||||
|
||||
///移除搜索标签
|
||||
void _handRemoveCustom(String tag) {
|
||||
var state = SelectionProvider.of(context);
|
||||
state.update((p) => p.currentMedicationsList.remove(tag));
|
||||
}
|
||||
|
||||
///是否标签选中
|
||||
bool getIsSelect(String tag) {
|
||||
var state = SelectionProvider.of(context);
|
||||
return state.userProfile.medicalInformationList.contains(tag);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var state = SelectionProvider.of(context);
|
||||
return StepContentCard(
|
||||
children: [
|
||||
CardTitle(title: "Medical Conditions"),
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 15),
|
||||
child: OptionList(
|
||||
widthFactor: 1,
|
||||
options: getOptions(widget.options, "medical_conditions"),
|
||||
selects: state.userProfile.medicalInformationList,
|
||||
onTap: _handToggle,
|
||||
),
|
||||
),
|
||||
CardTitle(title: "Current Medications"),
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 15),
|
||||
child: Row(
|
||||
spacing: 15,
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _otherController,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
decoration: InputDecoration(
|
||||
isCollapsed: true,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
||||
hintText: "Add medication...",
|
||||
filled: true,
|
||||
fillColor: Theme.of(context).colorScheme.surfaceContainerLow,
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: BorderSide(width: 1, color: Theme.of(context).colorScheme.surfaceContainer),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: BorderSide(width: 1, color: Theme.of(context).colorScheme.surfaceContainer),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: _handConfirmCustom,
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(RemixIcons.add_fill),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Wrap(
|
||||
runSpacing: 10,
|
||||
spacing: 10,
|
||||
children: state.userProfile.currentMedicationsList.map((item) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
_handRemoveCustom(item);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 3, horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.danger,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
spacing: 5,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
item,
|
||||
style: TextStyle(color: Colors.white, fontSize: 12),
|
||||
),
|
||||
Icon(
|
||||
RemixIcons.close_fill,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
155
lib/page/profile/my/my_page.dart
Normal file
155
lib/page/profile/my/my_page.dart
Normal file
@@ -0,0 +1,155 @@
|
||||
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:remixicon/remixicon.dart';
|
||||
|
||||
import '../../../router/config/route_paths.dart';
|
||||
import 'widget/title_card.dart';
|
||||
import 'widget/user_card.dart';
|
||||
|
||||
class MyPage extends StatefulWidget {
|
||||
const MyPage({super.key});
|
||||
|
||||
@override
|
||||
State<MyPage> createState() => _MyPageState();
|
||||
}
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
void _goEdit() async {
|
||||
await context.push(RoutePaths.myEdit, extra: _userProfile);
|
||||
_init();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
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 food 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,
|
||||
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: _userProfile.medicalInformationList,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 10),
|
||||
child: Text("Current Medications"),
|
||||
),
|
||||
buildTagList(
|
||||
emptyText: "No medications reported",
|
||||
tags: _userProfile.currentMedicationsList,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildTagList({
|
||||
required String emptyText,
|
||||
required List<String> tags,
|
||||
required Color color,
|
||||
}) {
|
||||
if (tags.isEmpty) {
|
||||
return Text(
|
||||
emptyText,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.success,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Wrap(
|
||||
spacing: 15,
|
||||
runSpacing: 15,
|
||||
children: tags.map((item) {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
item,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
50
lib/page/profile/my/widget/title_card.dart
Normal file
50
lib/page/profile/my/widget/title_card.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TitleCard extends StatelessWidget {
|
||||
final String title;
|
||||
final Widget icon;
|
||||
final Widget child;
|
||||
|
||||
const TitleCard({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.icon,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.all(15),
|
||||
margin: EdgeInsets.only(top: 15),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(color: Theme.of(context).colorScheme.shadow, blurRadius: 7),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 10),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
spacing: 10,
|
||||
children: [
|
||||
icon,
|
||||
Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
child,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
180
lib/page/profile/my/widget/user_card.dart
Normal file
180
lib/page/profile/my/widget/user_card.dart
Normal file
@@ -0,0 +1,180 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/api/dto/user_profile_dto.dart';
|
||||
import 'package:food_health/config/theme/custom_colors.dart';
|
||||
import 'package:food_health/providers/app_store.dart';
|
||||
import 'package:food_health/router/config/route_paths.dart';
|
||||
import 'package:food_health/utils/common.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
class UserCard extends StatefulWidget {
|
||||
final UserProfileDto detail;
|
||||
final Function() onEdit;
|
||||
|
||||
const UserCard({
|
||||
super.key,
|
||||
required this.detail,
|
||||
required this.onEdit,
|
||||
});
|
||||
|
||||
@override
|
||||
State<UserCard> createState() => _UserCardState();
|
||||
}
|
||||
|
||||
class _UserCardState extends State<UserCard> {
|
||||
void _goEdit() {
|
||||
widget.onEdit();
|
||||
}
|
||||
|
||||
void _handLogout() {
|
||||
var appStore = context.read<AppStore>();
|
||||
appStore.logout();
|
||||
context.go(RoutePaths.login);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Theme.of(context).colorScheme.shadow,
|
||||
blurRadius: 7,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
avatarWidget(),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(top: 12),
|
||||
child: Text(getNotEmpty(widget.detail.name) ?? "user", style: Theme.of(context).textTheme.titleMedium),
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(top: 5),
|
||||
child: Text(widget.detail.email ?? "", style: Theme.of(context).textTheme.labelMedium),
|
||||
),
|
||||
buildTitledTags(
|
||||
title: "Age Range",
|
||||
tag: getNotEmpty(widget.detail.ageRange),
|
||||
),
|
||||
buildTitledTags(
|
||||
title: "Activity Level",
|
||||
tag: getNotEmpty(widget.detail.activityLevel),
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
btnItem(
|
||||
title: "Edit Profile",
|
||||
icon: RemixIcons.edit_box_line,
|
||||
color: Colors.white,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
Theme.of(context).colorScheme.primary,
|
||||
Theme.of(context).colorScheme.primaryEnd,
|
||||
],
|
||||
),
|
||||
),
|
||||
onTap: _goEdit,
|
||||
),
|
||||
btnItem(
|
||||
title: "Logout",
|
||||
icon: RemixIcons.logout_circle_line,
|
||||
decoration: BoxDecoration(color: Theme.of(context).colorScheme.surfaceContainer),
|
||||
onTap: _handLogout,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///头像
|
||||
Widget avatarWidget() {
|
||||
return Container(
|
||||
width: 70,
|
||||
height: 70,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
Theme.of(context).colorScheme.primary,
|
||||
Theme.of(context).colorScheme.primaryEnd,
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
RemixIcons.user_3_line,
|
||||
color: Colors.white,
|
||||
size: 30,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///标题标签
|
||||
Widget buildTitledTags({
|
||||
required String title,
|
||||
String? tag,
|
||||
}) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(top: 20),
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: Theme.of(context).textTheme.bodyMedium),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 3),
|
||||
margin: const EdgeInsets.only(top: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerLow,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
tag ?? "Untitled",
|
||||
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///按钮
|
||||
Widget btnItem({
|
||||
required String title,
|
||||
required IconData icon,
|
||||
required BoxDecoration decoration,
|
||||
Color color = Colors.black,
|
||||
required Function() onTap,
|
||||
}) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(top: 15),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: decoration.copyWith(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, size: 20, color: color),
|
||||
SizedBox(width: 10),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(color: color, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
41
lib/page/record/detail/record_detail_page.dart
Normal file
41
lib/page/record/detail/record_detail_page.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:food_health/api/dto/food_scan_dto.dart';
|
||||
|
||||
import 'widget/detailed_analysis.dart';
|
||||
import 'widget/health_recommend.dart';
|
||||
import 'widget/result_chip.dart';
|
||||
|
||||
class RecordDetailPage extends StatefulWidget {
|
||||
final FoodScanDto detail;
|
||||
|
||||
const RecordDetailPage({super.key, required this.detail});
|
||||
|
||||
@override
|
||||
State<RecordDetailPage> createState() => _RecordDetailPageState();
|
||||
}
|
||||
|
||||
class _RecordDetailPageState extends State<RecordDetailPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
systemOverlayStyle: SystemUiOverlayStyle(
|
||||
statusBarIconBrightness: Brightness.dark, // 状态栏图标深色
|
||||
statusBarBrightness: Brightness.light, // iOS
|
||||
),
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.only(left: 15, right: 15, bottom: 15),
|
||||
children: [
|
||||
ResultChip(detail: widget.detail),
|
||||
DetailedAnalysis(detail: widget.detail),
|
||||
HealthRecommend(
|
||||
detail: widget.detail,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
76
lib/page/record/detail/widget/detailed_analysis.dart
Normal file
76
lib/page/record/detail/widget/detailed_analysis.dart
Normal file
@@ -0,0 +1,76 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/api/dto/food_scan_dto.dart';
|
||||
import 'package:markdown_widget/widget/markdown.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
class DetailedAnalysis extends StatelessWidget {
|
||||
final FoodScanDto detail;
|
||||
|
||||
const DetailedAnalysis({super.key, required this.detail});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: 20),
|
||||
padding: EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Theme.of(context).colorScheme.shadow,
|
||||
blurRadius: 10,
|
||||
offset: Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Icon(
|
||||
RemixIcons.eye_line,
|
||||
color: Theme.of(context).primaryColor,
|
||||
),
|
||||
Text(
|
||||
"Detailed Analysis",
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
MarkdownWidget(
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
data: detail.explanation ?? "",
|
||||
),
|
||||
Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Icon(RemixIcons.menu_2_line),
|
||||
Text(
|
||||
"Detected Ingredients",
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children: detail.ingredientsList!.map((item) {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerLow,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(item, style: Theme.of(context).textTheme.labelMedium),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
53
lib/page/record/detail/widget/health_recommend.dart
Normal file
53
lib/page/record/detail/widget/health_recommend.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/config/theme/custom_colors.dart';
|
||||
import 'package:markdown_widget/widget/markdown.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import '../../../../api/dto/food_scan_dto.dart';
|
||||
|
||||
class HealthRecommend extends StatelessWidget {
|
||||
final FoodScanDto detail;
|
||||
|
||||
const HealthRecommend({super.key, required this.detail});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: 20),
|
||||
padding: EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Theme.of(context).colorScheme.shadow,
|
||||
blurRadius: 10,
|
||||
offset: Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Icon(
|
||||
RemixIcons.heart_line,
|
||||
color: Theme.of(context).colorScheme.danger,
|
||||
),
|
||||
Text(
|
||||
"Health Recommendations",
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
MarkdownWidget(
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
data: detail.suggestions ?? "",
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
96
lib/page/record/detail/widget/result_chip.dart
Normal file
96
lib/page/record/detail/widget/result_chip.dart
Normal file
@@ -0,0 +1,96 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/api/dto/food_scan_dto.dart';
|
||||
import 'package:food_health/config/theme/custom_colors.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
class ResultChip extends StatelessWidget {
|
||||
final FoodScanDto detail;
|
||||
|
||||
const ResultChip({super.key, required this.detail});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Color currentColor = Colors.transparent; //设置主体颜色
|
||||
IconData iconData = Icons.check; //图标
|
||||
String title = "";
|
||||
String desc = "";
|
||||
|
||||
if (detail.foodType == 1) {
|
||||
currentColor = Theme.of(context).colorScheme.success;
|
||||
iconData = RemixIcons.shield_check_line;
|
||||
title = "Safe to Eat";
|
||||
desc = "This food appears safe for your health profile";
|
||||
} else if (detail.foodType == 2) {
|
||||
currentColor = Theme.of(context).colorScheme.warning;
|
||||
iconData = RemixIcons.error_warning_fill;
|
||||
title = "Proceed with Caution";
|
||||
desc = "This food may have some concerns for your health profile";
|
||||
} else if (detail.foodType == 3) {
|
||||
currentColor = Theme.of(context).colorScheme.danger;
|
||||
iconData = RemixIcons.close_circle_line;
|
||||
title = "Avoid This Food";
|
||||
desc = "This food is not recommended for your health profile";
|
||||
}
|
||||
return Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
color: currentColor.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: currentColor, width: 1),
|
||||
),
|
||||
child: Column(
|
||||
spacing: 20,
|
||||
children: [
|
||||
Container(
|
||||
width: 70,
|
||||
height: 70,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: currentColor,
|
||||
),
|
||||
child: Icon(
|
||||
iconData,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Text(
|
||||
desc,
|
||||
style: TextStyle(color: currentColor, fontSize: 14),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
SizedBox(
|
||||
width: 150,
|
||||
height: 150,
|
||||
child: Image.network(
|
||||
detail.imageUrl!,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(color: Theme.of(context).colorScheme.surfaceContainer),
|
||||
child: Icon(RemixIcons.error_warning_fill),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Text(
|
||||
detail.foodName ?? "",
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Text(
|
||||
detail.foodDesc ?? "",
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
78
lib/page/record/list/record_list_page.dart
Normal file
78
lib/page/record/list/record_list_page.dart
Normal file
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/api/dto/food_scan_dto.dart';
|
||||
import 'package:food_health/api/endpoints/food_api.dart';
|
||||
|
||||
import 'widget/record_list_card.dart';
|
||||
|
||||
class RecordListPage extends StatefulWidget {
|
||||
const RecordListPage({super.key});
|
||||
|
||||
@override
|
||||
State<RecordListPage> createState() => _RecordListPageState();
|
||||
}
|
||||
|
||||
class _RecordListPageState extends State<RecordListPage> with TickerProviderStateMixin {
|
||||
bool _loading = true;
|
||||
|
||||
//tab
|
||||
late TabController _tabController;
|
||||
final tabs = ["All", "Safe", "Warning", "Danger"];
|
||||
|
||||
//列表数据
|
||||
List<FoodScanDto> _record = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: tabs.length, vsync: this);
|
||||
_loadData();
|
||||
}
|
||||
|
||||
Future<void> _loadData() async {
|
||||
setState(() {
|
||||
_loading = true;
|
||||
});
|
||||
var res = await foodScanListApi();
|
||||
setState(() {
|
||||
_record = res;
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Food Check History"),
|
||||
bottom: TabBar(
|
||||
controller: _tabController,
|
||||
dividerColor: Colors.transparent,
|
||||
tabs: tabs.map((item) {
|
||||
return Tab(text: item);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
body: TabBarView(
|
||||
controller: _tabController,
|
||||
children: tabs.asMap().entries.map((entry) {
|
||||
var index = entry.key;
|
||||
var filterList = _record.where((item) {
|
||||
if (index == 0) return true;
|
||||
return item.foodType == index;
|
||||
}).toList();
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () => _loadData(),
|
||||
child: RecordListCard(
|
||||
loading: _loading,
|
||||
records: filterList,
|
||||
onRefresh: () {
|
||||
_loadData();
|
||||
},
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
157
lib/page/record/list/widget/record_list_card.dart
Normal file
157
lib/page/record/list/widget/record_list_card.dart
Normal file
@@ -0,0 +1,157 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/api/dto/food_scan_dto.dart';
|
||||
import 'package:food_health/config/theme/custom_colors.dart';
|
||||
import 'package:food_health/router/config/route_paths.dart';
|
||||
import 'package:food_health/widgets/common/async_image.dart';
|
||||
import 'package:food_health/widgets/ui_kit/empty/index.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
class RecordListCard extends StatelessWidget {
|
||||
final bool loading;
|
||||
final List<FoodScanDto> records;
|
||||
final Function() onRefresh;
|
||||
|
||||
const RecordListCard({
|
||||
super.key,
|
||||
required this.records,
|
||||
required this.loading,
|
||||
required this.onRefresh,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (loading) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
return Visibility(
|
||||
visible: records.isNotEmpty,
|
||||
replacement: Empty(
|
||||
child: ElevatedButton(
|
||||
onPressed: onRefresh,
|
||||
child: Text("Refresh"),
|
||||
),
|
||||
),
|
||||
child: ListView.separated(
|
||||
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
|
||||
itemBuilder: (context, index) {
|
||||
var item = records[index];
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
context.push(RoutePaths.detail, extra: item);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Theme.of(context).colorScheme.shadow,
|
||||
blurRadius: 4,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
spacing: 15,
|
||||
children: [
|
||||
Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 80,
|
||||
height: 80,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: AsyncImage(
|
||||
url: item.imageUrl!,
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: -5,
|
||||
top: -5,
|
||||
child: StatusWidget(
|
||||
type: item.foodType!,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
spacing: 10,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
item.foodName ?? "",
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
Text(
|
||||
item.foodDesc ?? "",
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) {
|
||||
return SizedBox(height: 15);
|
||||
},
|
||||
itemCount: records.length,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class StatusWidget extends StatelessWidget {
|
||||
final int type;
|
||||
|
||||
const StatusWidget({super.key, required this.type});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
IconData? iconData;
|
||||
Color? color;
|
||||
switch (type) {
|
||||
case 1:
|
||||
iconData = RemixIcons.shield_check_line;
|
||||
color = Theme.of(context).colorScheme.success;
|
||||
break;
|
||||
case 2:
|
||||
iconData = RemixIcons.error_warning_fill;
|
||||
color = Theme.of(context).colorScheme.warning;
|
||||
break;
|
||||
case 3:
|
||||
iconData = RemixIcons.close_circle_line;
|
||||
color = Theme.of(context).colorScheme.danger;
|
||||
break;
|
||||
}
|
||||
if (iconData == null) {
|
||||
return SizedBox();
|
||||
} else {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(5),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: color,
|
||||
),
|
||||
child: Icon(
|
||||
iconData,
|
||||
color: Colors.white,
|
||||
size: 15,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
23
lib/page/system/agree/agree_page.dart
Normal file
23
lib/page/system/agree/agree_page.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
class AgreePage extends StatelessWidget {
|
||||
final String title;
|
||||
final String url;
|
||||
|
||||
const AgreePage({super.key, required this.title, required this.url});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(title),
|
||||
),
|
||||
body: WebViewWidget(
|
||||
controller: WebViewController()
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
..loadRequest(Uri.parse(url)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
115
lib/page/system/login/login_code_page.dart
Normal file
115
lib/page/system/login/login_code_page.dart
Normal file
@@ -0,0 +1,115 @@
|
||||
import 'package:food_health/api/endpoints/user_api.dart';
|
||||
import 'package:food_health/api/network/safe.dart';
|
||||
import 'package:food_health/page/system/login/widget/widget.dart';
|
||||
import 'package:food_health/router/config/route_paths.dart';
|
||||
import 'package:food_health/widgets/ui_kit/button/custom_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../providers/app_store.dart';
|
||||
|
||||
class LoginCodePage extends StatefulWidget {
|
||||
final String email;
|
||||
final String password;
|
||||
|
||||
const LoginCodePage({super.key, required this.email, required this.password});
|
||||
|
||||
@override
|
||||
State<LoginCodePage> createState() => _LoginCodePageState();
|
||||
}
|
||||
|
||||
class _LoginCodePageState extends State<LoginCodePage> {
|
||||
final _codeController = TextEditingController();
|
||||
var _subLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_handSendCode();
|
||||
}
|
||||
|
||||
///发送验证码
|
||||
void _handSendCode() {
|
||||
sendEmailCodeApi(widget.email);
|
||||
EasyLoading.showSuccess("Send success");
|
||||
}
|
||||
|
||||
///提交
|
||||
void _handSubmit() async {
|
||||
if (_codeController.text.isNotEmpty) {
|
||||
setState(() {
|
||||
_subLoading = true;
|
||||
});
|
||||
var res = await safeRequest(
|
||||
registerApi(
|
||||
widget.email,
|
||||
widget.password,
|
||||
_codeController.text,
|
||||
),
|
||||
onError: (error) {
|
||||
setState(() {
|
||||
_subLoading = false;
|
||||
});
|
||||
},
|
||||
);
|
||||
var appStore = context.read<AppStore>();
|
||||
await appStore.setInfo(res);
|
||||
context.go(RoutePaths.layout);
|
||||
setState(() {
|
||||
_subLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.only(left: 20, right: 20, top: 40),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"Check your inbox",
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 20, bottom: 40),
|
||||
child: Text(
|
||||
"Enter the verification code we just sent to ${widget.email}.",
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
),
|
||||
),
|
||||
InputBox(hintText: "Code", controller: _codeController),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 20),
|
||||
child: CustomButton(
|
||||
loading: _subLoading,
|
||||
onPressed: _handSubmit,
|
||||
child: Text("Continue"),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 20),
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
_handSendCode();
|
||||
},
|
||||
child: Text(
|
||||
"Resend code",
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
293
lib/page/system/login/login_page.dart
Normal file
293
lib/page/system/login/login_page.dart
Normal file
@@ -0,0 +1,293 @@
|
||||
import 'package:food_health/api/endpoints/user_api.dart';
|
||||
import 'package:food_health/data/models/other_login_type.dart';
|
||||
import 'package:food_health/router/config/route_paths.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
|
||||
import '../../../providers/app_store.dart';
|
||||
import '../../../utils/common.dart';
|
||||
import '../../../widgets/common/app_backend.dart';
|
||||
import '../../../widgets/ui_kit/button/custom_button.dart';
|
||||
import 'widget/agreement_box.dart';
|
||||
import 'widget/widget.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
|
||||
@override
|
||||
State<LoginPage> createState() => _LoginPageState();
|
||||
}
|
||||
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
var _subLoading = false;
|
||||
|
||||
///协议
|
||||
bool _agree = false;
|
||||
|
||||
///谷歌登陆
|
||||
final GoogleSignIn _googleSignIn = GoogleSignIn.instance;
|
||||
|
||||
///邮箱输入框
|
||||
final TextEditingController _emailController = TextEditingController(text: "");
|
||||
final TextEditingController _passwordController = TextEditingController(text: "");
|
||||
|
||||
//显示密码
|
||||
var _hidePassword = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_ensureNetworkPermission();
|
||||
_initGoogleSign();
|
||||
}
|
||||
|
||||
/// 预触发 iOS 网络权限弹窗
|
||||
Future<bool> _ensureNetworkPermission() async {
|
||||
try {
|
||||
await Dio().get(
|
||||
'https://captive.apple.com/hotspot-detect.html',
|
||||
options: Options(
|
||||
sendTimeout: const Duration(seconds: 3),
|
||||
receiveTimeout: const Duration(seconds: 3),
|
||||
headers: {'Cache-Control': 'no-cache'},
|
||||
),
|
||||
);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void _initGoogleSign() {
|
||||
if (isAndroid()) {
|
||||
_googleSignIn.initialize(
|
||||
clientId: null,
|
||||
serverClientId: "512878764950-0bsl98c4q4p695mlmfn35qhmr2ld5n0o.apps.googleusercontent.com",
|
||||
);
|
||||
} else {
|
||||
_googleSignIn.initialize(
|
||||
clientId: "512878764950-u703jdn6imu33rthp94dg7cl5vmrc7rf.apps.googleusercontent.com",
|
||||
serverClientId: "512878764950-0bsl98c4q4p695mlmfn35qhmr2ld5n0o.apps.googleusercontent.com",
|
||||
);
|
||||
}
|
||||
|
||||
_googleSignIn.authenticationEvents
|
||||
.listen((_) {
|
||||
print("登陆成功");
|
||||
})
|
||||
.onError((error) {
|
||||
print('登录错误: $error');
|
||||
});
|
||||
}
|
||||
|
||||
///谷歌登录
|
||||
void _handleGoogleSignIn() async {
|
||||
if (!_agree) {
|
||||
EasyLoading.showToast('Please read and agree to the terms first.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 如果用户未登录,则启动标准的 Google 登录
|
||||
if (_googleSignIn.supportsAuthenticate()) {
|
||||
// 使用 authenticate() 进行认证
|
||||
GoogleSignInAccount? user = await _googleSignIn.authenticate();
|
||||
var auth = user.authentication;
|
||||
|
||||
// var res = await Dio().get("https://oauth2.googleapis.com/tokeninfo?id_token=${auth.idToken}");
|
||||
//登陆
|
||||
EasyLoading.show(status: "Logging in...");
|
||||
var res = await thirdLoginApi(auth.idToken!, OtherLoginType.google);
|
||||
EasyLoading.dismiss();
|
||||
_onLogin(res);
|
||||
}
|
||||
// } catch (e) {
|
||||
// if (e is GoogleSignInException) {
|
||||
// if (e.code == GoogleSignInExceptionCode.canceled) {
|
||||
// // 用户取消登录
|
||||
// print("User canceled login.");
|
||||
// } else {
|
||||
// // 其他错误
|
||||
// print("Google Sign-In error: $e");
|
||||
// }
|
||||
// } else {
|
||||
// print("Unknown error: $e");
|
||||
// }
|
||||
// }
|
||||
} catch (e) {
|
||||
EasyLoading.showError("Login failed");
|
||||
print("登录错误: $e");
|
||||
}
|
||||
}
|
||||
|
||||
///apple登录
|
||||
void _handAppleSignIn() async {
|
||||
if (!_agree) {
|
||||
EasyLoading.showToast('Please read and agree to the terms first.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final credential = await SignInWithApple.getAppleIDCredential(
|
||||
scopes: [
|
||||
AppleIDAuthorizationScopes.email,
|
||||
AppleIDAuthorizationScopes.fullName,
|
||||
],
|
||||
);
|
||||
EasyLoading.show(status: "Logging in...");
|
||||
var res = await thirdLoginApi(credential.identityToken!, OtherLoginType.apple);
|
||||
EasyLoading.dismiss();
|
||||
_onLogin(res);
|
||||
print('Apple Credential: ${credential.identityToken}');
|
||||
print('Apple Email: ${credential.email}');
|
||||
} catch (e) {
|
||||
print('Error during Apple sign-in: $e');
|
||||
}
|
||||
}
|
||||
|
||||
void _handSubmit() async {
|
||||
if (!_agree) {
|
||||
EasyLoading.showToast('Please read and agree to the terms first.');
|
||||
return;
|
||||
}
|
||||
if (_emailController.text.isEmpty) {
|
||||
//请输入邮箱
|
||||
EasyLoading.showError("Please enter your email");
|
||||
return;
|
||||
} else if (_passwordController.text.isEmpty) {
|
||||
EasyLoading.showError("Please enter your Password");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setState(() {
|
||||
_subLoading = true;
|
||||
});
|
||||
var isRegister = await checkRegisterApi(_emailController.text);
|
||||
if (!isRegister) {
|
||||
context.push(
|
||||
RoutePaths.loginCode,
|
||||
extra: {
|
||||
"email": _emailController.text,
|
||||
"password": _passwordController.text,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
var res = await loginApi(_emailController.text, _passwordController.text);
|
||||
_onLogin(res);
|
||||
}
|
||||
setState(() {
|
||||
_subLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_subLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
///登陆的操作
|
||||
void _onLogin(dynamic res) {
|
||||
var appStore = context.read<AppStore>();
|
||||
appStore.setInfo(res);
|
||||
context.go(RoutePaths.layout);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () => FocusScope.of(context).unfocus(),
|
||||
child: AppBackend(
|
||||
child: Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: SafeArea(
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.only(
|
||||
top: 0.07.sh,
|
||||
left: 20,
|
||||
right: 20,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
LogoBox(),
|
||||
PageHeader(),
|
||||
InputBox(
|
||||
hintText: "Email",
|
||||
controller: _emailController,
|
||||
),
|
||||
SizedBox(height: 15),
|
||||
InputBox(
|
||||
obscureText: _hidePassword,
|
||||
hintText: "Password",
|
||||
controller: _passwordController,
|
||||
suffix: InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_hidePassword = !_hidePassword;
|
||||
});
|
||||
},
|
||||
child: Icon(
|
||||
_hidePassword ? RemixIcons.eye_off_fill : RemixIcons.eye_fill,
|
||||
size: 20,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 20),
|
||||
height: 45,
|
||||
child: CustomButton(
|
||||
loading: _subLoading,
|
||||
round: false,
|
||||
onPressed: _handSubmit,
|
||||
child: Text("Continue"),
|
||||
),
|
||||
),
|
||||
LoginDivider(),
|
||||
OtherButton(
|
||||
title: "Continue with Google",
|
||||
icon: "assets/image/google.png",
|
||||
onTap: () {
|
||||
_handleGoogleSignIn();
|
||||
},
|
||||
),
|
||||
SizedBox(height: 15),
|
||||
OtherButton(
|
||||
title: "Continue with Apple",
|
||||
icon: "assets/image/apple.png",
|
||||
onTap: () {
|
||||
_handAppleSignIn();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 20,
|
||||
child: AgreementBox(
|
||||
checked: _agree,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_agree = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
66
lib/page/system/login/widget/agreement_box.dart
Normal file
66
lib/page/system/login/widget/agreement_box.dart
Normal file
@@ -0,0 +1,66 @@
|
||||
import 'package:food_health/router/config/route_paths.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
///勾中协议
|
||||
class AgreementBox extends StatelessWidget {
|
||||
final bool checked;
|
||||
final Function(bool) onChanged;
|
||||
|
||||
const AgreementBox({
|
||||
super.key,
|
||||
this.checked = false,
|
||||
required this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 25,
|
||||
child: Transform.scale(
|
||||
scale: 0.8,
|
||||
child: Checkbox(
|
||||
value: checked,
|
||||
shape: CircleBorder(),
|
||||
onChanged: (value) {
|
||||
onChanged(value!);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
children: [
|
||||
TextSpan(
|
||||
text: "I agree to the ",
|
||||
),
|
||||
TextSpan(
|
||||
text: "Terms",
|
||||
style: TextStyle(color: Theme.of(context).primaryColor),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () => context.push(
|
||||
RoutePaths.agreement,
|
||||
extra: {"title": "Terms of Service", "url": "https://support.curain.ai/privacy/derma/terms_service.html"},
|
||||
),
|
||||
),
|
||||
TextSpan(text: " & "),
|
||||
TextSpan(
|
||||
text: "Privacy Policy",
|
||||
style: TextStyle(color: Theme.of(context).primaryColor),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () => context.push(
|
||||
RoutePaths.agreement,
|
||||
extra: {"title": "Privacy", "url": "https://support.curain.ai/privacy/derma/privacy_policy.html"},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
166
lib/page/system/login/widget/widget.dart
Normal file
166
lib/page/system/login/widget/widget.dart
Normal file
@@ -0,0 +1,166 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
///登陆Box
|
||||
class LogoBox extends StatelessWidget {
|
||||
const LogoBox({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(bottom: 40),
|
||||
child: Column(
|
||||
children: [
|
||||
Image.asset(
|
||||
"assets/image/logo.png",
|
||||
width: 43,
|
||||
),
|
||||
Text(
|
||||
"FoodCura",
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
///头部文案
|
||||
class PageHeader extends StatelessWidget {
|
||||
const PageHeader({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(bottom: 30),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
"Create an account",
|
||||
style: TextStyle(fontWeight: FontWeight.w700),
|
||||
),
|
||||
Text(
|
||||
"Enter your email to sign up for this app",
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
///输入框
|
||||
class InputBox extends StatelessWidget {
|
||||
final bool obscureText;
|
||||
final String hintText;
|
||||
final TextEditingController controller;
|
||||
final Widget? suffix;
|
||||
|
||||
const InputBox({
|
||||
super.key,
|
||||
this.obscureText = false,
|
||||
required this.hintText,
|
||||
required this.controller,
|
||||
this.suffix,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//边框
|
||||
var inputBorder = OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
),
|
||||
);
|
||||
return TextField(
|
||||
controller: controller,
|
||||
maxLength: 100,
|
||||
obscureText: obscureText,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
decoration: InputDecoration(
|
||||
hintText: hintText,
|
||||
hintStyle: Theme.of(context).textTheme.labelMedium,
|
||||
counterText: '',
|
||||
border: inputBorder,
|
||||
enabledBorder: inputBorder,
|
||||
suffix: suffix,
|
||||
suffixIconConstraints: BoxConstraints(
|
||||
minWidth: 0,
|
||||
minHeight: 0,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
///分割线
|
||||
class LoginDivider extends StatelessWidget {
|
||||
const LoginDivider({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: 20, bottom: 20),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 1,
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
"or",
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 1,
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
///其他登陆按钮
|
||||
class OtherButton extends StatelessWidget {
|
||||
final Function() onTap;
|
||||
final String title;
|
||||
final String icon;
|
||||
|
||||
const OtherButton({
|
||||
super.key,
|
||||
required this.onTap,
|
||||
required this.title,
|
||||
required this.icon,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
),
|
||||
child: Row(
|
||||
spacing: 10,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Image.asset(icon, width: 20),
|
||||
Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
65
lib/page/system/splash/splash_page.dart
Normal file
65
lib/page/system/splash/splash_page.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'package:food_health/providers/app_store.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../config/app_context.dart';
|
||||
import '../../../router/config/route_paths.dart';
|
||||
import '../../../router/routes.dart';
|
||||
|
||||
class SplashPage extends StatefulWidget {
|
||||
const SplashPage({super.key});
|
||||
|
||||
@override
|
||||
State<SplashPage> createState() => _SplashPageState();
|
||||
}
|
||||
|
||||
class _SplashPageState extends State<SplashPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
init();
|
||||
}
|
||||
|
||||
void init() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
AppContext.setContent(navigatorKey.currentState!.context);
|
||||
//效验
|
||||
AppStore appStore = context.read<AppStore>();
|
||||
await appStore.init();
|
||||
if (!mounted) return;
|
||||
if (appStore.token.isEmpty) {
|
||||
context.go(RoutePaths.login);
|
||||
} else {
|
||||
context.go(RoutePaths.layout);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Image.asset(
|
||||
"assets/image/logo.png",
|
||||
width: 68.w,
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 16),
|
||||
child: Text(
|
||||
"Demacare",
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user