基本完成
This commit is contained in:
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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user