100 lines
2.8 KiB
Dart
100 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_common/widget/common_widget.dart';
|
|
import 'package:food_hub_app/models/recipe.dart';
|
|
import 'package:food_hub_app/widgets/common/image.dart';
|
|
import 'package:liquid_glass_widgets/liquid_glass_widgets.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 List<String> imageUrls =
|
|
recipe.recordList.reversed.map((record) => record.imageUrl).toList();
|
|
|
|
final colors = Theme.of(context).colorScheme;
|
|
|
|
return GlassCard(
|
|
padding: EdgeInsetsGeometry.all(10),
|
|
useOwnLayer: true,
|
|
settings: LiquidGlassSettings(glassColor: colors.surface),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
CommonImage(imageUrls: imageUrls, index: 0),
|
|
SizedBox(height: 8),
|
|
InkWell(
|
|
onTap: () => navigatorToRecipeDetail(context),
|
|
child: _buildRecipeContent(context),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildRecipeContent(BuildContext context) {
|
|
final colors = Theme.of(context).colorScheme;
|
|
final textTheme = Theme.of(context).textTheme;
|
|
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
recipe.name,
|
|
style: textTheme.titleMedium,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 5),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
_buildIconText(
|
|
icon: Icons.food_bank,
|
|
text: recipe.category,
|
|
color: colors.primary,
|
|
),
|
|
const SizedBox(width: 12),
|
|
_buildIconText(
|
|
icon: Icons.note_add,
|
|
text: recipe.recordList.length.toString(),
|
|
color: colors.primary,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 通用图标文本组件
|
|
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)),
|
|
],
|
|
);
|
|
}
|
|
}
|