feat:更新菜谱显示模块
This commit is contained in:
@@ -43,8 +43,7 @@ class _RecipeDetailState extends State<RecipeDetailPage> {
|
||||
Future<void> refreshRecipeDetail() async {
|
||||
// 获取参数
|
||||
final args = ModalRoute.of(context)?.settings.arguments as Map;
|
||||
final recipeId = args['id'];
|
||||
final result = await queryRecipeByIdApi(recipeId);
|
||||
final result = await queryRecipeByIdApi(args['id']);
|
||||
|
||||
setState(() {
|
||||
recipe = result;
|
||||
@@ -71,13 +70,8 @@ class _RecipeDetailState extends State<RecipeDetailPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('菜谱信息'),
|
||||
leading: IconButton(
|
||||
icon: Icon(Icons.arrow_back),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
),
|
||||
appBar: AppBar(title: Text('菜谱信息')),
|
||||
backgroundColor: Color(0xFFF4F4F4),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(padding: EdgeInsets.all(5), child: _buildRecipeDetail()),
|
||||
),
|
||||
@@ -89,12 +83,11 @@ class _RecipeDetailState extends State<RecipeDetailPage> {
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_buildTitleSection(),
|
||||
SizedBox(height: 10),
|
||||
_buildInfoCard(
|
||||
context,
|
||||
icon: Icons.info,
|
||||
title: "基础信息",
|
||||
content: _buildTag(context, title: recipe.category),
|
||||
content: buildTag(context, recipe.category),
|
||||
),
|
||||
_buildInfoCard(
|
||||
context,
|
||||
@@ -131,20 +124,6 @@ class _RecipeDetailState extends State<RecipeDetailPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTag(BuildContext context, {required String title}) {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Color.lerp(Theme.of(context).primaryColor, Colors.white, 0.8),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
title,
|
||||
style: TextStyle(color: Theme.of(context).primaryColor),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTitleSection() {
|
||||
return Text(
|
||||
recipe.name,
|
||||
@@ -165,16 +144,14 @@ class _RecipeDetailState extends State<RecipeDetailPage> {
|
||||
child: Text(title, style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
),
|
||||
if (materials.isEmpty)
|
||||
_buildTag(context, title: '无')
|
||||
buildTag(context, '无')
|
||||
else
|
||||
Wrap(
|
||||
spacing: 8.0,
|
||||
runSpacing: 8.0,
|
||||
children:
|
||||
materials
|
||||
.map(
|
||||
(m) => _buildTag(context, title: '${m.name} ${m.amount}'),
|
||||
)
|
||||
.map((m) => buildTag(context, '${m.name} ${m.amount}'))
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
@@ -229,7 +206,7 @@ class _RecipeDetailState extends State<RecipeDetailPage> {
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(icon, color: Theme.of(context).primaryColor),
|
||||
Icon(icon, color: Theme.of(context).colorScheme.primary),
|
||||
const SizedBox(width: 5),
|
||||
Text(
|
||||
title,
|
||||
@@ -240,7 +217,7 @@ class _RecipeDetailState extends State<RecipeDetailPage> {
|
||||
SizedBox(height: 5),
|
||||
content,
|
||||
],
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user