feat:增加加载中组件
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_hub_app/apis/recipe.dart';
|
||||
import 'package:food_hub_app/config/app_config.dart';
|
||||
import 'package:food_hub_app/models/recipe.dart';
|
||||
import 'package:food_hub_app/provider/food_provider.dart';
|
||||
import 'package:food_hub_app/widgets/common/image.dart';
|
||||
import 'package:food_hub_app/widgets/common/index.dart';
|
||||
import 'package:food_hub_app/widgets/common/year_selector.dart';
|
||||
import 'package:timelines_plus/timelines_plus.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class RecipeTimeline extends StatefulWidget {
|
||||
const RecipeTimeline({super.key});
|
||||
@@ -15,24 +15,7 @@ class RecipeTimeline extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _RecipeTimeline extends State<RecipeTimeline> {
|
||||
List<FoodRecord> recordList = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
refreshRecord(DateTime.now().year);
|
||||
}
|
||||
|
||||
Future<void> refreshRecord(int year) async {
|
||||
final result = await queryRecordApi("$year-01-01", "$year-12-31");
|
||||
setState(() {
|
||||
recordList = result;
|
||||
});
|
||||
}
|
||||
|
||||
Widget buildTimelineCard(BuildContext context, FoodRecord record) {
|
||||
final imageUrl = '${AppConfig.imageBaseUrl}${record.imageUrl}';
|
||||
|
||||
return buildCard(
|
||||
context: context,
|
||||
child: Column(
|
||||
@@ -58,7 +41,7 @@ class _RecipeTimeline extends State<RecipeTimeline> {
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
buildNetworkImage(context, imageUrl),
|
||||
buildNetworkImage(context, record.imageUrl),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -93,8 +76,7 @@ class _RecipeTimeline extends State<RecipeTimeline> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget _buildContent(FoodProvider provider) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -102,9 +84,25 @@ class _RecipeTimeline extends State<RecipeTimeline> {
|
||||
initialYear: DateTime.now().year,
|
||||
minYear: 2000,
|
||||
maxYear: 2100,
|
||||
onYearChanged: (year) => refreshRecord(year),
|
||||
onYearChanged:
|
||||
(year) =>
|
||||
provider.refreshRecordList("$year-01-01", "$year-12-31"),
|
||||
),
|
||||
Expanded(child: buildTimeline(context, recordList)),
|
||||
Expanded(child: buildTimeline(context, provider.recordList)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<FoodProvider>();
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
if (provider.isLoading)
|
||||
buildLoadingIndicator(context)
|
||||
else
|
||||
_buildContent(provider),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user