登录流程已全部重构
This commit is contained in:
30
lib/pages/home/home_page.dart
Normal file
30
lib/pages/home/home_page.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:food_health/pages/home/widget/home_header.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../widgets/shared/app_backend.dart';
|
||||
import '../../widgets/shared/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/pages/home/widget/home_header.dart
Normal file
28
lib/pages/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 Check",
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
223
lib/pages/home/widget/upload_panel.dart
Normal file
223
lib/pages/home/widget/upload_panel.dart
Normal file
@@ -0,0 +1,223 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.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/color_ext.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> {
|
||||
//步骤
|
||||
int _step = 0;
|
||||
Timer? timer;
|
||||
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
|
||||
///打开相机拍照
|
||||
void _handTakePhoto() async {
|
||||
try {
|
||||
var photo = await _picker.pickImage(source: ImageSource.camera);
|
||||
if (photo != null) {
|
||||
_startDetect(photo.path);
|
||||
}
|
||||
} on PlatformException catch (e) {
|
||||
EasyLoading.showToast(e.message ?? "");
|
||||
}
|
||||
}
|
||||
|
||||
///选择图片
|
||||
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: 'Uploading Image...', maskType: EasyLoadingMaskType.clear);
|
||||
|
||||
// 1秒后第二句
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
EasyLoading.show(status: 'Checking Security...', maskType: EasyLoadingMaskType.clear);
|
||||
});
|
||||
|
||||
// 2秒后第三句
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
EasyLoading.show(
|
||||
status: 'All set! Just a moment..', maskType: EasyLoadingMaskType.clear);
|
||||
});
|
||||
// 真正的上传/分析
|
||||
var res = await foodScanApi(result!);
|
||||
|
||||
// 上传完成后,强制切换为最后一句
|
||||
EasyLoading.show(status: 'Analyzing your data…', maskType: EasyLoadingMaskType.clear);
|
||||
|
||||
// 停留一下再进入详情
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
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, and HElC 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/pages/profile/edit/data/state.dart
Normal file
25
lib/pages/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!;
|
||||
}
|
||||
}
|
||||
304
lib/pages/profile/edit/my_edit_page.dart
Normal file
304
lib/pages/profile/edit/my_edit_page.dart
Normal file
@@ -0,0 +1,304 @@
|
||||
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/endpoints/profile_api.dart';
|
||||
import 'package:food_health/config/theme/color_ext.dart';
|
||||
import 'package:food_health/pages/profile/edit/widget/food_allergies.dart';
|
||||
import 'package:food_health/stores/user_store.dart';
|
||||
import 'package:food_health/widgets/shared/app_backend.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import 'data/state.dart';
|
||||
import 'widget/dietary_preferences.dart';
|
||||
import 'widget/health_profile.dart';
|
||||
|
||||
class MyEditPage extends StatefulWidget {
|
||||
const MyEditPage({super.key});
|
||||
|
||||
@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: "Tell us about your allergies so we can help keep you safe",
|
||||
),
|
||||
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 {
|
||||
UserStore userStore = context.read<UserStore>();
|
||||
selectionState = SelectionState(userStore.profile);
|
||||
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(true);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_loading) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
return PopScope(
|
||||
canPop: selectionState.userProfile.qStatus == 1,
|
||||
onPopInvokedWithResult: (didPop, __) async {
|
||||
if (didPop) return;
|
||||
},
|
||||
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: 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: _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 customize 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/pages/profile/edit/util/common.dart
Normal file
9
lib/pages/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/pages/profile/edit/widget/common.dart
Normal file
100
lib/pages/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/pages/profile/edit/widget/dietary_preferences.dart
Normal file
127
lib/pages/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/pages/profile/edit/widget/food_allergies.dart
Normal file
144
lib/pages/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/color_ext.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 (_otherController.text.isNotEmpty && !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 a 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/pages/profile/edit/widget/health_profile.dart
Normal file
151
lib/pages/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/color_ext.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 (_otherController.text.isNotEmpty && !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 a custom 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(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
156
lib/pages/profile/my/my_page.dart
Normal file
156
lib/pages/profile/my/my_page.dart
Normal file
@@ -0,0 +1,156 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/config/theme/color_ext.dart';
|
||||
import 'package:food_health/stores/user_store.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:remixicon/remixicon.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 {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return SafeArea(
|
||||
child: ListView(
|
||||
padding: EdgeInsets.all(15),
|
||||
children: [
|
||||
UserCard(),
|
||||
Consumer<UserStore>(
|
||||
builder: (context, store, _) {
|
||||
return Column(
|
||||
children: [
|
||||
TitleCard(
|
||||
title: "Food Allergies",
|
||||
icon: Icon(
|
||||
RemixIcons.shield_line,
|
||||
color: Theme
|
||||
.of(context)
|
||||
.colorScheme
|
||||
.danger,
|
||||
),
|
||||
child: buildTagList(
|
||||
emptyText: "No allergies reported",
|
||||
tags: store.profile.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: store.profile.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: 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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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/pages/profile/my/widget/title_card.dart
Normal file
50
lib/pages/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,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
248
lib/pages/profile/my/widget/user_card.dart
Normal file
248
lib/pages/profile/my/widget/user_card.dart
Normal file
@@ -0,0 +1,248 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:food_health/api/dto/user_profile_dto.dart';
|
||||
import 'package:food_health/api/endpoints/user_api.dart';
|
||||
import 'package:food_health/config/theme/color_ext.dart';
|
||||
import 'package:food_health/stores/app_store.dart';
|
||||
import 'package:food_health/stores/user_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 {
|
||||
const UserCard({super.key});
|
||||
|
||||
@override
|
||||
State<UserCard> createState() => _UserCardState();
|
||||
}
|
||||
|
||||
class _UserCardState extends State<UserCard> {
|
||||
void _goEditProfile() async {
|
||||
var isUpload = await context.push(RoutePaths.myEdit);
|
||||
if (isUpload == true && mounted) {
|
||||
UserStore userStore = context.read<UserStore>();
|
||||
userStore.init();
|
||||
}
|
||||
}
|
||||
|
||||
///退出登陆
|
||||
void _handLogout() async {
|
||||
await showCupertinoDialog(
|
||||
context: context,
|
||||
builder: (_) => CupertinoAlertDialog(
|
||||
title: Text("Log Out?"),
|
||||
content: Text("Are you sure you want to log out? You’ll need to sign in again to access your account."),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
child: Text("Cancel"),
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
child: Text("Log Out"),
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
var appStore = context.read<AppStore>();
|
||||
appStore.logout();
|
||||
context.go(RoutePaths.login);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///注销账号
|
||||
void _handDelete() async {
|
||||
await showCupertinoDialog(
|
||||
context: context,
|
||||
builder: (_) => CupertinoAlertDialog(
|
||||
title: Text("Delete Account?"),
|
||||
content: Text("Are you sure you want to delete your account? You won’t be able to recover your account."),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
child: Text("Cancel"),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
child: Text("Delete"),
|
||||
onPressed: () async {
|
||||
context.pop();
|
||||
EasyLoading.show();
|
||||
await deleteAccountApi();
|
||||
EasyLoading.dismiss();
|
||||
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: Consumer<UserStore>(
|
||||
builder: (context, store, _) {
|
||||
return Column(
|
||||
children: [
|
||||
avatarWidget(),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(top: 12),
|
||||
child: Text(getNotEmpty(store.profile.name) ?? "user", style: Theme.of(context).textTheme.titleMedium),
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(top: 5),
|
||||
child: Text(store.profile.email ?? "", style: Theme.of(context).textTheme.labelMedium),
|
||||
),
|
||||
buildTitledTags(
|
||||
title: "Age Range",
|
||||
tag: getNotEmpty(store.profile.ageRange),
|
||||
),
|
||||
buildTitledTags(
|
||||
title: "Activity Level",
|
||||
tag: getNotEmpty(store.profile.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: _goEditProfile,
|
||||
),
|
||||
btnItem(
|
||||
title: "Logout",
|
||||
icon: RemixIcons.logout_circle_line,
|
||||
decoration: BoxDecoration(color: Theme.of(context).colorScheme.surfaceContainer),
|
||||
onTap: _handLogout,
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(top: 10),
|
||||
child: InkWell(
|
||||
onTap: _handDelete,
|
||||
child: Text(
|
||||
"Delete Account ",
|
||||
style: TextStyle(color: Colors.red, fontSize: 14),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///头像
|
||||
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/pages/record/detail/record_detail_page.dart
Normal file
41
lib/pages/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,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
86
lib/pages/record/detail/widget/detailed_analysis.dart
Normal file
86
lib/pages/record/detail/widget/detailed_analysis.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
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 ?? "",
|
||||
),
|
||||
Visibility(
|
||||
visible: detail.ingredientsList!.isNotEmpty,
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Icon(RemixIcons.menu_2_line),
|
||||
Text(
|
||||
"Detected Ingredients",
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 10),
|
||||
child: 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/pages/record/detail/widget/health_recommend.dart
Normal file
53
lib/pages/record/detail/widget/health_recommend.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/config/theme/color_ext.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/pages/record/detail/widget/result_chip.dart
Normal file
96
lib/pages/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/color_ext.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/pages/record/list/record_list_page.dart
Normal file
78
lib/pages/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(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
158
lib/pages/record/list/widget/record_list_card.dart
Normal file
158
lib/pages/record/list/widget/record_list_card.dart
Normal file
@@ -0,0 +1,158 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/api/dto/food_scan_dto.dart';
|
||||
import 'package:food_health/config/theme/color_ext.dart';
|
||||
import 'package:food_health/router/config/route_paths.dart';
|
||||
import 'package:food_health/widgets/shared/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(
|
||||
cacheExtent: 2000,
|
||||
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/pages/system/agree/agree_page.dart
Normal file
23
lib/pages/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)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
223
lib/pages/system/code/login_code_page.dart
Normal file
223
lib/pages/system/code/login_code_page.dart
Normal file
@@ -0,0 +1,223 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:food_health/api/endpoints/user_api.dart';
|
||||
import 'package:food_health/api/network/safe.dart';
|
||||
import 'package:food_health/l10n/l10n.dart';
|
||||
import 'package:food_health/router/config/route_paths.dart';
|
||||
import 'package:food_health/stores/app_store.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.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 List<FocusNode> _focusNodes = List.generate(4, (_) => FocusNode());
|
||||
final List<TextEditingController> _controllers = List.generate(
|
||||
4,
|
||||
(_) => TextEditingController(),
|
||||
);
|
||||
|
||||
//倒计时
|
||||
int _count = 60;
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_handSendCode();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
_handClear();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
///小输入框改变时
|
||||
void _onChanged(String value, int index) async {
|
||||
//一键复制
|
||||
if (value.length == 4) {
|
||||
_handlePaste(value);
|
||||
}
|
||||
//提交
|
||||
if (value.isNotEmpty && index == 3) {
|
||||
_handSubmit();
|
||||
return;
|
||||
}
|
||||
// 自动跳到下一格
|
||||
if (value.length == 1 && index < 3) {
|
||||
_focusNodes[index + 1].requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePaste(String pastedText) {
|
||||
// 只取前4位数字
|
||||
final digits = pastedText.replaceAll(RegExp(r'[^0-9]'), '');
|
||||
for (int i = 0; i < 4; i++) {
|
||||
_controllers[i].text = i < digits.length ? digits[i] : '';
|
||||
}
|
||||
if (digits.length >= 4) {
|
||||
_focusNodes[3].requestFocus();
|
||||
_handSubmit();
|
||||
} else if (digits.isNotEmpty) {
|
||||
_focusNodes[digits.length].requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
///删除键
|
||||
void _onDelete(KeyEvent event, int index) {
|
||||
if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.backspace) {
|
||||
final currentController = _controllers[index];
|
||||
if (currentController.text.isEmpty && index > 0) {
|
||||
_focusNodes[index - 1].requestFocus();
|
||||
_controllers[index - 1].clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///发送验证码
|
||||
void _handSendCode() {
|
||||
if (_count != 60) {
|
||||
return;
|
||||
}
|
||||
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
|
||||
setState(() {
|
||||
_count--;
|
||||
});
|
||||
if (_count == 0) {
|
||||
setState(() {
|
||||
_count = 60;
|
||||
});
|
||||
timer.cancel();
|
||||
}
|
||||
});
|
||||
sendEmailCodeApi(widget.email);
|
||||
EasyLoading.showToast(L10n.of.code_success);
|
||||
}
|
||||
|
||||
///提交
|
||||
void _handSubmit() async {
|
||||
String code = _controllers.map((controller) => controller.text).join();
|
||||
if (code.length == 4) {
|
||||
EasyLoading.show();
|
||||
var res = await safeRequest(
|
||||
registerApi(
|
||||
widget.email,
|
||||
widget.password,
|
||||
code,
|
||||
),
|
||||
onError: (error) {
|
||||
_handClear();
|
||||
EasyLoading.showToast(L10n.of.code_error);
|
||||
},
|
||||
);
|
||||
var appStore = context.read<AppStore>();
|
||||
await appStore.setInfo(res);
|
||||
context.go(RoutePaths.layout);
|
||||
}
|
||||
}
|
||||
|
||||
///清空
|
||||
void _handClear() {
|
||||
for (var controller in _controllers) {
|
||||
controller.clear();
|
||||
}
|
||||
_focusNodes.first.requestFocus();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: ListView(
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
padding: EdgeInsets.all(20),
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 20),
|
||||
child: Text(L10n.of.code_title, style: Theme.of(context).textTheme.titleLarge),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 60),
|
||||
child: Text(
|
||||
"${L10n.of.code_tip} ${widget.email}",
|
||||
style: Theme.of(context).textTheme.labelLarge,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
spacing: 20,
|
||||
children: List.generate(4, (index) {
|
||||
return Expanded(
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: KeyboardListener(
|
||||
focusNode: FocusNode(),
|
||||
onKeyEvent: (event) {
|
||||
_onDelete(event, index);
|
||||
},
|
||||
child: TextField(
|
||||
controller: _controllers[index],
|
||||
focusNode: _focusNodes[index],
|
||||
textAlign: TextAlign.center,
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 4,
|
||||
style: TextStyle(fontSize: 32),
|
||||
decoration: InputDecoration(
|
||||
counterText: "",
|
||||
border: InputBorder.none,
|
||||
isCollapsed: true,
|
||||
),
|
||||
onChanged: (value) {
|
||||
_onChanged(value, index);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 30),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: _handSendCode,
|
||||
child: Visibility(
|
||||
visible: _count != 60,
|
||||
replacement: Text(
|
||||
L10n.of.code_send_code,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
child: Text(
|
||||
"${L10n.of.code_send_code}(${_count}s)",
|
||||
style: Theme.of(context).textTheme.labelLarge,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
69
lib/pages/system/intro/intro_page.dart
Normal file
69
lib/pages/system/intro/intro_page.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/l10n/l10n.dart';
|
||||
import 'package:food_health/router/config/route_paths.dart';
|
||||
import 'package:food_health/widgets/ui_kit/button/app_button.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class IntroPage extends StatefulWidget {
|
||||
const IntroPage({super.key});
|
||||
|
||||
@override
|
||||
State<IntroPage> createState() => _IntroPageState();
|
||||
}
|
||||
|
||||
class _IntroPageState extends State<IntroPage> {
|
||||
void _onTap() {
|
||||
context.go(RoutePaths.login);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
backgroundColor: Colors.white,
|
||||
body: SafeArea(
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(50),
|
||||
child: Image.asset("assets/image/bg/intro_bg.png"),
|
||||
),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 20),
|
||||
child: Text(
|
||||
L10n.of.welcome_title,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
L10n.of.welcome_desc,
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
),
|
||||
Container(
|
||||
height: 50,
|
||||
margin: EdgeInsets.only(top: 20),
|
||||
child: AppButton(
|
||||
onPressed: _onTap,
|
||||
child: Text(L10n.of.welcome_button_text),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
289
lib/pages/system/login/login_page.dart
Normal file
289
lib/pages/system/login/login_page.dart
Normal file
@@ -0,0 +1,289 @@
|
||||
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:food_health/api/endpoints/user_api.dart';
|
||||
import 'package:food_health/data/models/other_login_type.dart';
|
||||
import 'package:food_health/l10n/l10n.dart';
|
||||
import 'package:food_health/pages/system/login/widgets/login_input.dart';
|
||||
import 'package:food_health/router/config/route_paths.dart';
|
||||
import 'package:food_health/stores/app_store.dart';
|
||||
import 'package:food_health/widgets/ui_kit/button/app_button.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 '../../../utils/common.dart';
|
||||
import 'widgets/login_agree.dart';
|
||||
import 'widgets/login_other.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
|
||||
@override
|
||||
State<LoginPage> createState() => _LoginPageState();
|
||||
}
|
||||
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
Logger logger = Logger();
|
||||
|
||||
var _subLoading = false;
|
||||
|
||||
///邮箱输入框
|
||||
final TextEditingController _emailController = TextEditingController();
|
||||
final TextEditingController _passwordController = TextEditingController();
|
||||
|
||||
//显示密码
|
||||
bool _hidePassword = true;
|
||||
|
||||
///谷歌登陆
|
||||
final GoogleSignIn _googleSignIn = GoogleSignIn.instance;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_emailController.addListener(() {
|
||||
setState(() {});
|
||||
});
|
||||
_passwordController.addListener(() {
|
||||
setState(() {});
|
||||
});
|
||||
_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-1ke7slf0c6dlmchnuk0fqh3fe954gcf2.apps.googleusercontent.com",
|
||||
serverClientId:
|
||||
"512878764950-0bsl98c4q4p695mlmfn35qhmr2ld5n0o.apps.googleusercontent.com",
|
||||
);
|
||||
}
|
||||
|
||||
_googleSignIn.authenticationEvents
|
||||
.listen((_) {
|
||||
logger.d("登陆成功");
|
||||
})
|
||||
.onError((error) {
|
||||
logger.e("登陆错误: $error");
|
||||
});
|
||||
}
|
||||
|
||||
///谷歌登录
|
||||
void _handGoogleSignIn() async {
|
||||
try {
|
||||
// 如果用户未登录,则启动标准的 Google 登录
|
||||
if (_googleSignIn.supportsAuthenticate()) {
|
||||
// 使用 authenticate() 进行认证
|
||||
GoogleSignInAccount? user = await _googleSignIn.authenticate();
|
||||
var auth = user.authentication;
|
||||
|
||||
//登陆
|
||||
EasyLoading.show();
|
||||
var res = await thirdLoginApi(auth.idToken!, OtherLoginType.google);
|
||||
EasyLoading.dismiss();
|
||||
_onLogin(res);
|
||||
}
|
||||
} catch (e) {
|
||||
EasyLoading.showError(L10n.of.login_error_text);
|
||||
logger.e("登录错误: $e");
|
||||
}
|
||||
}
|
||||
|
||||
///apple登录
|
||||
void _handAppleSignIn() async {
|
||||
try {
|
||||
final credential = await SignInWithApple.getAppleIDCredential(
|
||||
scopes: [
|
||||
AppleIDAuthorizationScopes.email,
|
||||
AppleIDAuthorizationScopes.fullName,
|
||||
],
|
||||
);
|
||||
EasyLoading.show();
|
||||
var res = await thirdLoginApi(credential.identityToken!, OtherLoginType.apple);
|
||||
EasyLoading.dismiss();
|
||||
_onLogin(res);
|
||||
logger.d('Apple Credential: ${credential.identityToken}');
|
||||
logger.d('Apple Email: ${credential.email}');
|
||||
} catch (e) {
|
||||
logger.e("登录错误: $e");
|
||||
}
|
||||
}
|
||||
|
||||
void _handSubmit() async {
|
||||
if (_emailController.text.isEmpty) {
|
||||
//请输入邮箱
|
||||
EasyLoading.showToast(L10n.of.login_email_hint);
|
||||
return;
|
||||
} else if (_passwordController.text.isEmpty) {
|
||||
EasyLoading.showToast(L10n.of.login_password_hint);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setState(() {
|
||||
_subLoading = true;
|
||||
});
|
||||
var isRegister = await checkRegisterApi(_emailController.text);
|
||||
if (!isRegister && mounted) {
|
||||
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 Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: SafeArea(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(
|
||||
left: 20,
|
||||
right: 20,
|
||||
top: 0.08.sh,
|
||||
bottom: 40,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 40),
|
||||
child: Text(
|
||||
L10n.of.login_title,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
),
|
||||
LoginInput(
|
||||
hintText: L10n.of.login_email_hint,
|
||||
controller: _emailController,
|
||||
suffix: Visibility(
|
||||
visible: _emailController.text.isNotEmpty,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
_emailController.clear();
|
||||
},
|
||||
child: Icon(
|
||||
RemixIcons.close_circle_fill,
|
||||
size: 20,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
LoginInput(
|
||||
hintText: L10n.of.login_password_hint,
|
||||
controller: _passwordController,
|
||||
obscureText: _hidePassword,
|
||||
suffix: InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_hidePassword = !_hidePassword;
|
||||
});
|
||||
},
|
||||
child: Icon(
|
||||
_hidePassword ? RemixIcons.eye_off_fill : RemixIcons.eye_fill,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 40),
|
||||
height: 50,
|
||||
child: AppButton(
|
||||
disabled: _emailController.text.isEmpty || _passwordController.text.isEmpty,
|
||||
loading: _subLoading,
|
||||
onPressed: _handSubmit,
|
||||
child: Text(L10n.of.login_button),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
margin: EdgeInsets.only(top: 20),
|
||||
alignment: Alignment.center,
|
||||
child: LoginAgree(),
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
LoginDivider(),
|
||||
Row(
|
||||
spacing: 20,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
OtherButton(
|
||||
onTap: () {
|
||||
_handGoogleSignIn();
|
||||
},
|
||||
icon: "assets/image/google.png",
|
||||
),
|
||||
OtherButton(
|
||||
onTap: () {
|
||||
_handAppleSignIn();
|
||||
},
|
||||
icon: "assets/image/apple.png",
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
50
lib/pages/system/login/widgets/login_agree.dart
Normal file
50
lib/pages/system/login/widgets/login_agree.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/l10n/l10n.dart';
|
||||
import 'package:food_health/router/config/route_paths.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class LoginAgree extends StatelessWidget {
|
||||
const LoginAgree({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RichText(
|
||||
text: TextSpan(
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
children: [
|
||||
TextSpan(
|
||||
text: "${L10n.of.login_tip_start} ",
|
||||
),
|
||||
TextSpan(
|
||||
text: L10n.of.login_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/foodcura/terms_service.html",
|
||||
},
|
||||
),
|
||||
),
|
||||
TextSpan(text: " ${L10n.of.login_and} "),
|
||||
TextSpan(
|
||||
text: L10n.of.login_privacy,
|
||||
style: TextStyle(color: Theme.of(context).primaryColor),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () => context.push(
|
||||
RoutePaths.agreement,
|
||||
extra: {
|
||||
"title": "Privacy",
|
||||
"url": "https://support.curain.ai/privacy/foodcura/privacy_policy.html",
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
46
lib/pages/system/login/widgets/login_input.dart
Normal file
46
lib/pages/system/login/widgets/login_input.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LoginInput extends StatelessWidget {
|
||||
final bool obscureText;
|
||||
final String hintText;
|
||||
final TextEditingController controller;
|
||||
final Widget? suffix;
|
||||
|
||||
const LoginInput({
|
||||
super.key,
|
||||
this.obscureText = false,
|
||||
required this.hintText,
|
||||
required this.controller,
|
||||
this.suffix,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextField(
|
||||
controller: controller,
|
||||
obscureText: obscureText,
|
||||
maxLength: 100,
|
||||
decoration: InputDecoration(
|
||||
hintText: hintText,
|
||||
hintStyle: Theme.of(context).textTheme.labelLarge?.copyWith(fontSize: 16),
|
||||
counterText: '',
|
||||
filled: true,
|
||||
fillColor: Theme.of(context).colorScheme.surfaceContainer,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(60),
|
||||
borderSide: BorderSide.none, // 去掉边框
|
||||
),
|
||||
isCollapsed: true,
|
||||
contentPadding: EdgeInsets.symmetric(vertical: 14, horizontal: 20),
|
||||
suffixIcon: Container(
|
||||
padding: EdgeInsets.only(right: 20),
|
||||
child: suffix,
|
||||
),
|
||||
suffixIconConstraints: BoxConstraints(
|
||||
minWidth: 0,
|
||||
minHeight: 0,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
67
lib/pages/system/login/widgets/login_other.dart
Normal file
67
lib/pages/system/login/widgets/login_other.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/l10n/l10n.dart';
|
||||
|
||||
///分割线
|
||||
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(
|
||||
L10n.of.login_other_login,
|
||||
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 icon;
|
||||
|
||||
const OtherButton({
|
||||
super.key,
|
||||
required this.onTap,
|
||||
required this.icon,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: 45,
|
||||
padding: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
),
|
||||
),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: Image.asset(icon),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
58
lib/pages/system/splash/splash_page.dart
Normal file
58
lib/pages/system/splash/splash_page.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:food_health/stores/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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
26
lib/pages/system/test_page.dart
Normal file
26
lib/pages/system/test_page.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_health/l10n/app_localizations.dart';
|
||||
|
||||
class TestPage extends StatefulWidget {
|
||||
const TestPage({super.key});
|
||||
|
||||
@override
|
||||
State<TestPage> createState() => _TestPageState();
|
||||
}
|
||||
|
||||
class _TestPageState extends State<TestPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Text(
|
||||
AppLocalizations.of(context)?.login_title ?? "",
|
||||
style: TextStyle(
|
||||
fontSize: 50,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user