Basic details page

This commit is contained in:
LittleSheep 2024-08-15 01:38:29 +08:00
parent 7797c1b635
commit 07f8112c7a
7 changed files with 79 additions and 12 deletions

View File

@ -62,10 +62,10 @@ class Aggregations {
}
class DataType {
int branded;
int surveyFndds;
int srLegacy;
int foundation;
int? branded;
int? surveyFndds;
int? srLegacy;
int? foundation;
DataType({
required this.branded,

View File

@ -0,0 +1,45 @@
import 'package:dietary_guard/models/food_data.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class FoodDetailsScreen extends StatelessWidget {
final FoodData item;
const FoodDetailsScreen({super.key, required this.item});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(item.description),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('nutrients'.tr).paddingOnly(left: 24, right: 24, bottom: 8),
Expanded(
child: ListView.builder(
itemCount: item.foodNutrients.length,
itemBuilder: (context, idx) {
final entry = item.foodNutrients[idx];
final unitName = unitNameValues.reverse[entry.unitName];
return ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
title: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(entry.nutrientName),
const SizedBox(width: 6),
Badge(label: Text('#${entry.nutrientId}'))
],
),
subtitle: Text('${entry.nutrientNumber} ${unitName}'),
);
},
),
)
],
).paddingSymmetric(vertical: 24),
);
}
}

View File

@ -1,5 +1,7 @@
import 'package:animations/animations.dart';
import 'package:dietary_guard/controllers/food_data.dart';
import 'package:dietary_guard/models/food_data.dart';
import 'package:dietary_guard/screens/food/details.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
@ -57,22 +59,31 @@ class _QueryScreenState extends State<QueryScreen> {
).paddingSymmetric(horizontal: 24),
if (_isLoading)
const SizedBox(
width: 20,
height: 20,
width: 28,
height: 28,
child: CircularProgressIndicator(strokeWidth: 3),
).paddingSymmetric(vertical: 16)
).paddingSymmetric(vertical: 24)
else
Expanded(
child: ListView.builder(
itemCount: _foodData.length,
itemBuilder: (context, index) {
final item = _foodData[index];
return ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
return OpenContainer(
closedBuilder: (_, open) => ListTile(
contentPadding:
const EdgeInsets.symmetric(horizontal: 24),
title: Text(item.description),
subtitle: Text(
DateFormat("yyyy-MM-dd").format(item.publishedDate),
),
onTap: () => open(),
),
openBuilder: (_, __) => FoodDetailsScreen(item: item),
openElevation: 0,
closedElevation: 0,
closedColor: Colors.transparent,
openColor: Colors.transparent,
);
},
).paddingOnly(top: 8),

View File

@ -5,4 +5,5 @@ const i18nEnglish = {
'settingsApplied': 'Settings Applied',
'apply': 'Apply',
'searchHistoryNotIncluded': 'Search History not Included, yet',
'nutrients': 'Nutrients',
};

View File

@ -5,4 +5,5 @@ const i18nSimplifiedChinese = {
'settingsApplied': '设置已应用',
'apply': '应用',
'searchHistoryNotIncluded': '搜索记录还没实现',
'nutrients': '营养物质',
};

View File

@ -1,6 +1,14 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
animations:
dependency: "direct main"
description:
name: animations
sha256: d3d6dcfb218225bbe68e87ccf6378bbb2e32a94900722c5f81611dad089911cb
url: "https://pub.dev"
source: hosted
version: "2.0.11"
async:
dependency: transitive
description:

View File

@ -41,6 +41,7 @@ dependencies:
sqflite: ^2.3.3+1
dio: ^5.6.0
intl: ^0.19.0
animations: ^2.0.11
dev_dependencies:
flutter_test: