121 lines
3.6 KiB
Dart
121 lines
3.6 KiB
Dart
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/image.dart';
|
|
import 'package:food_hub_app/widgets/common/index.dart';
|
|
|
|
class RecipeCard extends StatelessWidget {
|
|
final RecipeSummary recipe;
|
|
|
|
const RecipeCard({super.key, required this.recipe});
|
|
|
|
void navigatorToRecipeDetail(BuildContext context) {
|
|
Navigator.pushNamed(context, '/recipeDetail', arguments: {'id': recipe.id});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final String firstImageUrl = recipe.recordList.first.imageUrl;
|
|
|
|
Widget buildRecipeContent(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
recipe.name,
|
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
_buildIconText(
|
|
icon: Icons.food_bank,
|
|
text: recipe.category,
|
|
color: Color(0xFF6A5ACD),
|
|
),
|
|
const SizedBox(width: 12),
|
|
_buildIconText(
|
|
icon: Icons.thumb_up_alt_outlined,
|
|
text: recipe.likeCount.toString(),
|
|
color: Color(0xFFDC143C),
|
|
),
|
|
const SizedBox(width: 12),
|
|
_buildIconText(
|
|
icon: Icons.star_outline,
|
|
text: recipe.favouriteCount.toString(),
|
|
color: Color(0xFF20B2AA),
|
|
),
|
|
const SizedBox(width: 12),
|
|
_buildIconText(
|
|
icon: Icons.comment_outlined,
|
|
text: recipe.commentCount.toString(),
|
|
color: Color(0xFFDAC570),
|
|
),
|
|
],
|
|
),
|
|
Row(
|
|
children: [
|
|
_buildIconText(
|
|
icon: Icons.date_range,
|
|
text: recipe.recordList[0].date,
|
|
color: Color(0xFF32CD32),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
return buildCard(
|
|
context: context,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
buildNetworkImage(
|
|
context,
|
|
'${AppConfig.imageBaseUrl}/$firstImageUrl',
|
|
),
|
|
SizedBox(height: 8),
|
|
GestureDetector(
|
|
onTap: () => navigatorToRecipeDetail(context),
|
|
child: buildRecipeContent(context),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// 通用图标文本组件
|
|
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)),
|
|
],
|
|
);
|
|
}
|
|
}
|