65 lines
1.9 KiB
Dart
65 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_common/utils/sp_utils.dart';
|
|
import 'package:flutter_common/widget/common_widget.dart';
|
|
import 'package:food_hub_app/provider/food_provider.dart';
|
|
import 'package:food_hub_app/widgets/moment/card.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class MomentUserPage extends StatefulWidget {
|
|
const MomentUserPage({super.key});
|
|
|
|
@override
|
|
State<MomentUserPage> createState() => _MomentUserPageState();
|
|
}
|
|
|
|
class _MomentUserPageState extends State<MomentUserPage> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
// 初始化加载数据
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
context.read<FoodProvider>().queryMomentByUserId(SPUtil.getInt('userId'));
|
|
});
|
|
}
|
|
|
|
Widget _buildMomentList(FoodProvider provider) {
|
|
return ListView.separated(
|
|
itemCount: provider.momentList.length,
|
|
separatorBuilder: (context, index) => SizedBox(height: 8),
|
|
itemBuilder: (context, index) {
|
|
return MomentCard(moment: provider.momentList[index], isUser: true);
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final provider = context.watch<FoodProvider>();
|
|
|
|
// 空状态显示
|
|
if (provider.momentList.isEmpty) {
|
|
return buildEmptyData();
|
|
}
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('我的朋友圈', style: const TextStyle(color: Colors.white)),
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
|
onPressed: () => Navigator.pop(context),
|
|
),
|
|
),
|
|
backgroundColor: const Color(0xFFF5F5F5),
|
|
body:
|
|
provider.isLoading
|
|
? buildLoadingIndicator()
|
|
: Padding(
|
|
padding: const EdgeInsets.all(10),
|
|
child: CommonCard(child: _buildMomentList(provider)),
|
|
),
|
|
);
|
|
}
|
|
}
|