48 lines
1.2 KiB
Dart
48 lines
1.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:food_hub_app/api/recipe.dart';
|
|
import 'package:food_hub_app/models/recipe.dart';
|
|
import 'package:food_hub_app/widgets/recipe/card.dart';
|
|
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
|
|
|
class RecipeList extends StatefulWidget {
|
|
const RecipeList({super.key});
|
|
|
|
@override
|
|
State<RecipeList> createState() => _RecipeListState();
|
|
}
|
|
|
|
class _RecipeListState extends State<RecipeList> {
|
|
List<Recipe> recipeList = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
refreshRecipeList();
|
|
}
|
|
|
|
Future<void> refreshRecipeList() async {
|
|
final result = await queryRecipeApi(RecipeQuery(category: ""));
|
|
|
|
setState(() {
|
|
recipeList = result;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (recipeList.isEmpty) {
|
|
return const TDEmpty(type: TDEmptyType.plain, emptyText: '暂无数据');
|
|
} else {
|
|
return ListView.separated(
|
|
itemCount: recipeList.length,
|
|
itemBuilder: (context, index) {
|
|
return RecipeCard(recipe: recipeList[index]);
|
|
},
|
|
separatorBuilder: (BuildContext context, int index) {
|
|
return SizedBox(height: 10);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
}
|