feat:更新记录UI布局
This commit is contained in:
@@ -171,9 +171,9 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
isSelected
|
||||
? Colors.blue
|
||||
? Theme.of(context).primaryColor
|
||||
: isToday
|
||||
? Colors.grey[200]
|
||||
? Colors.grey[300]
|
||||
: Colors.transparent,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
@@ -184,7 +184,7 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
// 日期数字
|
||||
Text(
|
||||
day.day.toString(),
|
||||
style: TextStyle(color: isSelected ? Colors.white : Colors.black87),
|
||||
style: TextStyle(color: isSelected ? Colors.white : Colors.black),
|
||||
),
|
||||
// 底部红点 - 只在指定日期显示
|
||||
if (shouldShowRedDot)
|
||||
@@ -207,7 +207,6 @@ class _RecipeCalendarState extends State<RecipeCalendar> {
|
||||
return Column(
|
||||
children: [
|
||||
Card(elevation: 0, color: Colors.white, child: recipeCalendar()),
|
||||
const SizedBox(height: 10),
|
||||
Expanded(child: dailyItem()),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_hub_app/config/app_config.dart';
|
||||
|
||||
import 'package:food_hub_app/models/recipe.dart';
|
||||
import 'package:food_hub_app/widgets/common/index.dart';
|
||||
@@ -19,7 +20,7 @@ class RecipeCard extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Image.network(
|
||||
'http://172.29.101.108:8100/${recipe.recordList[0].imageUrl}',
|
||||
'${AppConfig.baseApiUrl}/${recipe.recordList[0].imageUrl}',
|
||||
height: 200,
|
||||
width: double.infinity,
|
||||
fit: BoxFit.contain,
|
||||
|
||||
@@ -34,14 +34,11 @@ class _RecipeListState extends State<RecipeList> {
|
||||
if (recipeList.isEmpty) {
|
||||
return const TDEmpty(type: TDEmptyType.plain, emptyText: '暂无数据');
|
||||
} else {
|
||||
return ListView.separated(
|
||||
return ListView.builder(
|
||||
itemCount: recipeList.length,
|
||||
itemBuilder: (context, index) {
|
||||
return RecipeCard(recipe: recipeList[index]);
|
||||
},
|
||||
separatorBuilder: (context, index) {
|
||||
return const SizedBox(height: 10);
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_hub_app/api/recipe.dart';
|
||||
import 'package:food_hub_app/config/app_config.dart';
|
||||
import 'package:food_hub_app/models/recipe.dart';
|
||||
import 'package:food_hub_app/widgets/common/index.dart';
|
||||
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||||
@@ -18,11 +19,11 @@ class _RecipeTimeline extends State<RecipeTimeline> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
refreshRecord();
|
||||
refreshRecord(DateTime.now().year);
|
||||
}
|
||||
|
||||
Future<void> refreshRecord() async {
|
||||
final result = await queryRecordApi("2025-01-01", "2025-07-08");
|
||||
Future<void> refreshRecord(int year) async {
|
||||
final result = await queryRecordApi("$year-01-01", "$year-12-31");
|
||||
setState(() {
|
||||
recordList = result;
|
||||
});
|
||||
@@ -36,18 +37,15 @@ class _RecipeTimeline extends State<RecipeTimeline> {
|
||||
initialYear: DateTime.now().year,
|
||||
minYear: 2000,
|
||||
maxYear: 2100,
|
||||
onYearChanged: (year) {
|
||||
print('选中的年份: $year');
|
||||
},
|
||||
accentColor: Colors.blue,
|
||||
onYearChanged: (year) => refreshRecord(year)
|
||||
),
|
||||
Expanded(child: TimelineContainer(recordList))
|
||||
Expanded(child: timelineContainer(recordList)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget TimelineContainer(List<Record> recordList) {
|
||||
Widget timelineContainer(List<Record> recordList) {
|
||||
if (recordList.isEmpty) {
|
||||
return const TDEmpty(type: TDEmptyType.plain, emptyText: '暂无数据');
|
||||
} else {
|
||||
@@ -76,6 +74,30 @@ class TimelineCard extends StatelessWidget {
|
||||
|
||||
const TimelineCard({super.key, required this.record});
|
||||
|
||||
Widget cardContent() {
|
||||
return Card(
|
||||
elevation: 0,
|
||||
color: Colors.white,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(record.name, style: TextStyle(fontSize: 16)),
|
||||
const SizedBox(height: 5),
|
||||
Image.network(
|
||||
'${AppConfig.baseApiUrl}/${record.imageUrl}',
|
||||
width: double.infinity,
|
||||
height: 250,
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder:
|
||||
(context, error, stackTrace) => errorImageContainer(250),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
@@ -89,28 +111,7 @@ class TimelineCard extends StatelessWidget {
|
||||
record.date,
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
Card(
|
||||
elevation: 0,
|
||||
color: Colors.white,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(record.name, style: TextStyle(fontSize: 16)),
|
||||
const SizedBox(height: 5),
|
||||
Image.network(
|
||||
'http://172.29.101.108:8100/${record.imageUrl}',
|
||||
width: double.infinity,
|
||||
height: 250,
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder:
|
||||
(context, error, stackTrace) =>
|
||||
errorImageContainer(250),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
cardContent(),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -123,7 +124,6 @@ class YearSelector extends StatefulWidget {
|
||||
final int? minYear;
|
||||
final int? maxYear;
|
||||
final Function(int) onYearChanged;
|
||||
final Color? accentColor;
|
||||
|
||||
const YearSelector({
|
||||
super.key,
|
||||
@@ -131,17 +131,16 @@ class YearSelector extends StatefulWidget {
|
||||
required this.onYearChanged,
|
||||
this.minYear,
|
||||
this.maxYear,
|
||||
this.accentColor,
|
||||
});
|
||||
|
||||
@override
|
||||
State<YearSelector> createState() => _YearSelectorState();
|
||||
}
|
||||
|
||||
// SingleTickerProviderStateMixin 动画控制器
|
||||
class _YearSelectorState extends State<YearSelector>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late int _currentYear;
|
||||
late Color _accentColor;
|
||||
|
||||
// 用于动画效果
|
||||
late AnimationController _animationController;
|
||||
@@ -151,9 +150,6 @@ class _YearSelectorState extends State<YearSelector>
|
||||
void initState() {
|
||||
super.initState();
|
||||
_currentYear = widget.initialYear;
|
||||
_accentColor = widget.accentColor ?? Theme
|
||||
.of(context)
|
||||
.primaryColor;
|
||||
|
||||
// 初始化动画控制器
|
||||
_animationController = AnimationController(
|
||||
@@ -228,12 +224,13 @@ class _YearSelectorState extends State<YearSelector>
|
||||
child: Text(
|
||||
'$_currentYear',
|
||||
style: TextStyle(
|
||||
fontSize: 28,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _accentColor,
|
||||
color: Theme.of(context).primaryColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
TDButton(
|
||||
icon: Icons.chevron_right,
|
||||
size: TDButtonSize.small,
|
||||
|
||||
Reference in New Issue
Block a user