feat:更新记录页面模块
This commit is contained in:
23
lib/widgets/recipe/recipe_calendar.dart
Normal file
23
lib/widgets/recipe/recipe_calendar.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
|
||||
class RecipeCalendar extends StatelessWidget {
|
||||
const RecipeCalendar({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Card(
|
||||
elevation: 0,
|
||||
color: Colors.white,
|
||||
child: TableCalendar(
|
||||
firstDay: DateTime.utc(2010, 10, 16),
|
||||
lastDay: DateTime.utc(2030, 3, 14),
|
||||
focusedDay: DateTime.now(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
156
lib/widgets/recipe/recipe_card.dart
Normal file
156
lib/widgets/recipe/recipe_card.dart
Normal file
@@ -0,0 +1,156 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:food_hub_app/models/recipe.dart';
|
||||
|
||||
class RecipeCard extends StatelessWidget {
|
||||
final Recipe recipe;
|
||||
|
||||
const RecipeCard({super.key, required this.recipe});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
elevation: 0,
|
||||
color: Colors.white,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Image.network(
|
||||
recipe.imageUrl,
|
||||
height: 200,
|
||||
width: double.infinity,
|
||||
fit: BoxFit.contain,
|
||||
errorBuilder:
|
||||
(context, error, stackTrace) => Container(
|
||||
height: 200,
|
||||
color: Colors.grey[200],
|
||||
child: const Icon(Icons.food_bank, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
const Divider(
|
||||
height: 1,
|
||||
thickness: 1,
|
||||
color: Colors.green,
|
||||
indent: 0,
|
||||
endIndent: 0,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
recipe.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
maxLines: 1, // 限制单行,避免挤压按钮
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit, size: 14),
|
||||
color: Colors.white,
|
||||
style: ButtonStyle(
|
||||
backgroundColor: WidgetStateProperty.all(
|
||||
Colors.green,
|
||||
),
|
||||
shape: WidgetStateProperty.all(CircleBorder()),
|
||||
minimumSize: WidgetStateProperty.all(Size(20, 20)),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.book, size: 14),
|
||||
color: Colors.white,
|
||||
style: ButtonStyle(
|
||||
backgroundColor: WidgetStateProperty.all(
|
||||
Colors.green,
|
||||
),
|
||||
shape: WidgetStateProperty.all(CircleBorder()),
|
||||
minimumSize: WidgetStateProperty.all(Size(20, 20)),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
_buildIconText(
|
||||
icon: Icons.food_bank,
|
||||
text: recipe.category,
|
||||
color: Colors.green,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
_buildIconText(
|
||||
icon: Icons.thumb_up_alt_outlined,
|
||||
text: recipe.likeCount.toString(),
|
||||
color: Colors.red,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
_buildIconText(
|
||||
icon: Icons.star_outline,
|
||||
text: recipe.favoriteCount.toString(),
|
||||
color: Colors.blue,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
_buildIconText(
|
||||
icon: Icons.comment_outlined,
|
||||
text: recipe.commentCount.toString(),
|
||||
color: Colors.deepOrange,
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
_buildIconText(
|
||||
icon: Icons.date_range,
|
||||
text: recipe.date,
|
||||
color: Colors.red,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 通用图标文本组件
|
||||
Widget _buildIconText({
|
||||
required IconData icon,
|
||||
required String text,
|
||||
Color color = Colors.grey, // 默认灰色
|
||||
double iconSize = 16,
|
||||
double textSize = 16,
|
||||
double spacing = 2, // 图标与文本间距
|
||||
}) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, size: iconSize, color: color),
|
||||
SizedBox(width: spacing),
|
||||
Text(text, style: TextStyle(fontSize: textSize, color: color)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
22
lib/widgets/recipe/recipe_list.dart
Normal file
22
lib/widgets/recipe/recipe_list.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:food_hub_app/models/recipe.dart';
|
||||
import 'package:food_hub_app/widgets/recipe/recipe_card.dart';
|
||||
|
||||
class RecipeList extends StatelessWidget {
|
||||
final List<Recipe> recipeList;
|
||||
|
||||
const RecipeList({super.key, required this.recipeList});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.separated(
|
||||
itemCount: recipeList.length,
|
||||
itemBuilder: (context, index) {
|
||||
return RecipeCard(recipe: recipeList[index]);
|
||||
},
|
||||
separatorBuilder: (context, index) {
|
||||
return const SizedBox(height: 10);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
45
lib/widgets/recipe/recipe_segment.dart
Normal file
45
lib/widgets/recipe/recipe_segment.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:custom_sliding_segmented_control/custom_sliding_segmented_control.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_hub_app/models/recipe.dart';
|
||||
|
||||
class RecipeSegment extends StatelessWidget {
|
||||
final ViewType selectedViewType;
|
||||
final Function(ViewType) onViewTypeChanged;
|
||||
|
||||
const RecipeSegment({super.key, required this.selectedViewType, required this.onViewTypeChanged});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CustomSlidingSegmentedControl<int>(
|
||||
initialValue: 1,
|
||||
children: {
|
||||
1: SizedBox(
|
||||
width: 50,
|
||||
child: Text('菜谱', textAlign: TextAlign.center),
|
||||
),
|
||||
2: SizedBox(
|
||||
width: 50,
|
||||
child: Text('日历', textAlign: TextAlign.center),
|
||||
),
|
||||
3: SizedBox(
|
||||
width: 50,
|
||||
child: Text('时间轴', textAlign: TextAlign.center),
|
||||
),
|
||||
},
|
||||
decoration: BoxDecoration(
|
||||
color: CupertinoColors.lightBackgroundGray,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
thumbDecoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
duration: Duration(milliseconds: 300),
|
||||
curve: Curves.easeInToLinear,
|
||||
onValueChanged: (value) {
|
||||
onViewTypeChanged(ViewType.values[value - 1]);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
71
lib/widgets/recipe/recipe_timeline.dart
Normal file
71
lib/widgets/recipe/recipe_timeline.dart
Normal file
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_hub_app/models/recipe.dart';
|
||||
import 'package:timelines_plus/timelines_plus.dart';
|
||||
|
||||
class RecipeTimeline extends StatelessWidget {
|
||||
final List<Recipe> recipeList;
|
||||
|
||||
const RecipeTimeline({super.key, required this.recipeList});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Timeline.tileBuilder(
|
||||
theme: TimelineThemeData(nodePosition: 0, indicatorPosition: 0),
|
||||
builder: TimelineTileBuilder.connected(
|
||||
itemCount: recipeList.length,
|
||||
connectorBuilder:
|
||||
(context, index, type) => Connector.solidLine(thickness: 2),
|
||||
indicatorBuilder: (context, index) {
|
||||
return Indicator.dot(size: 12.0);
|
||||
},
|
||||
contentsBuilder: (context, index) {
|
||||
return TimelineCard(recipe: recipeList[index]);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TimelineCard extends StatelessWidget {
|
||||
final Recipe recipe;
|
||||
|
||||
const TimelineCard({super.key, required this.recipe});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 10, bottom: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
recipe.date,
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
Card(
|
||||
elevation: 0,
|
||||
color: Colors.white,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(recipe.name, style: TextStyle(fontSize: 16)),
|
||||
const SizedBox(height: 10),
|
||||
Image.network(
|
||||
recipe.imageUrl,
|
||||
width: double.infinity,
|
||||
height: 250,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user