feat:更新个人主页模块
This commit is contained in:
@@ -24,6 +24,13 @@ Future<List<Moment>> queryMomentListApi() {
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<Moment>> queryMomentListByUserIdApi(int userId) {
|
||||
return httpUtil.get<List<Moment>>(
|
||||
"/moment/$userId",
|
||||
converter: (data) => convertList<Moment>(data, Moment.fromJson),
|
||||
);
|
||||
}
|
||||
|
||||
Future<PageMoment> queryMomentByPageApi(int currentPage, int pageSize) {
|
||||
return httpUtil.get<PageMoment>(
|
||||
"/moment/page",
|
||||
|
||||
12
lib/apis/user.dart
Normal file
12
lib/apis/user.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
import 'package:flutter_common/utils/http_utils.dart';
|
||||
import 'package:food_hub_app/config/app_config.dart';
|
||||
import 'package:food_hub_app/models/session.dart';
|
||||
|
||||
final httpUtil = HttpUtil(baseUrl: AppConfig.baseApiUrl);
|
||||
|
||||
Future<User> queryUserApi(int number) {
|
||||
return httpUtil.get<User>(
|
||||
"/user/$number",
|
||||
converter: (data) => User.fromJson(data),
|
||||
);
|
||||
}
|
||||
@@ -5,8 +5,8 @@ class AppConfig {
|
||||
// http://14.103.235.151:81/food-service
|
||||
// static const String baseApiUrl = "http://14.103.235.151:81/food-service";
|
||||
// static const String baseApiUrl = "http://192.168.1.3:8100";
|
||||
// static const String baseApiUrl = "https://cxx0822.iepose.cn/food-api";
|
||||
static const String baseApiUrl = "http://192.168.1.4:8083";
|
||||
static const String baseApiUrl = "https://cxx0822.iepose.cn/food-api";
|
||||
// static const String baseApiUrl = "http://192.168.1.4:8083";
|
||||
// static const String baseApiUrl = "http://192.168.1.103:8083";
|
||||
static const String rustfsIp = '14.103.235.151';
|
||||
static const String rustfsFileUrl = 'http://14.103.235.151:9100';
|
||||
|
||||
@@ -3,23 +3,15 @@ import 'package:food_hub_app/provider/food_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class AppActions extends StatefulWidget {
|
||||
const AppActions({super.key});
|
||||
final int pageIndex;
|
||||
|
||||
const AppActions({super.key, required this.pageIndex});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => AppActionsState();
|
||||
}
|
||||
|
||||
class AppActionsState extends State<AppActions> {
|
||||
void _buildBottomSheet(FoodProvider provider) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||
),
|
||||
builder: (context) => _buildBottomSheetBody(provider),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBottomSheetBody(FoodProvider provider) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final provider = context.watch<FoodProvider>();
|
||||
@@ -33,25 +25,44 @@ class AppActionsState extends State<AppActions> {
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
ListTile(
|
||||
leading: Icon(Icons.book, color: colors.primary),
|
||||
title: const Text('新增菜谱'),
|
||||
onTap: () => _handleAddRecipe(provider),
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.note_add, color: colors.primary),
|
||||
title: const Text('新增记录'),
|
||||
onTap: () => _handleAddRecord(provider),
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.group, color: colors.primary),
|
||||
title: const Text('发布朋友圈'),
|
||||
onTap: () => _handleAddMoment(provider),
|
||||
),
|
||||
if (widget.pageIndex == 0)
|
||||
ListTile(
|
||||
leading: Icon(Icons.book, color: colors.primary),
|
||||
title: const Text('新增菜谱'),
|
||||
onTap: () => _handleAddRecipe(provider),
|
||||
),
|
||||
if (widget.pageIndex == 0)
|
||||
ListTile(
|
||||
leading: Icon(Icons.note_add, color: colors.primary),
|
||||
title: const Text('新增记录'),
|
||||
onTap: () => _handleAddRecord(provider),
|
||||
),
|
||||
if (widget.pageIndex == 2)
|
||||
ListTile(
|
||||
leading: Icon(Icons.group, color: colors.primary),
|
||||
title: const Text('发布朋友圈'),
|
||||
onTap: () => _handleAddMoment(provider),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _onPressAdd(FoodProvider provider) {
|
||||
if (widget.pageIndex == 0) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||
),
|
||||
builder: (context) => _buildBottomSheetBody(provider),
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.pageIndex == 2) {
|
||||
_handleAddMoment(provider);
|
||||
}
|
||||
}
|
||||
|
||||
void _handleAddRecipe(FoodProvider provider) {
|
||||
// provider.resetRecordForm();
|
||||
// Navigator.pop(context);
|
||||
@@ -68,7 +79,6 @@ class AppActionsState extends State<AppActions> {
|
||||
void _handleAddMoment(FoodProvider provider) {
|
||||
provider.resetMomentForm();
|
||||
provider.isEditing = false;
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamed(context, "/momentForm");
|
||||
}
|
||||
|
||||
@@ -84,12 +94,11 @@ class AppActionsState extends State<AppActions> {
|
||||
// 搜索功能
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.add, color: Colors.white),
|
||||
onPressed: () {
|
||||
_buildBottomSheet(provider);
|
||||
},
|
||||
),
|
||||
if (widget.pageIndex == 0 || widget.pageIndex == 2)
|
||||
IconButton(
|
||||
icon: Icon(Icons.add, color: Colors.white),
|
||||
onPressed: () => _onPressAdd(provider),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@ import 'package:flutter_common/provider/theme_provider.dart';
|
||||
import 'package:flutter_common/utils/sp_utils.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:food_hub_app/provider/food_provider.dart';
|
||||
import 'package:food_hub_app/provider/user_provider.dart';
|
||||
import 'package:food_hub_app/views/home.dart';
|
||||
import 'package:food_hub_app/views/login.dart';
|
||||
import 'package:food_hub_app/views/moment.dart';
|
||||
import 'package:food_hub_app/views/moment_form.dart';
|
||||
import 'package:food_hub_app/views/moment_user.dart';
|
||||
import 'package:food_hub_app/views/record_form.dart';
|
||||
import 'package:food_hub_app/views/recipe_detail.dart';
|
||||
import 'package:form_builder_validators/form_builder_validators.dart';
|
||||
@@ -23,6 +25,7 @@ void main() async {
|
||||
providers: [
|
||||
ChangeNotifierProvider(create: (context) => FoodProvider()),
|
||||
ChangeNotifierProvider(create: (context) => ThemeProvider()),
|
||||
ChangeNotifierProvider(create: (context) => UserProvider()),
|
||||
],
|
||||
child: MyApp(),
|
||||
),
|
||||
@@ -65,7 +68,8 @@ class MyApp extends StatelessWidget {
|
||||
'/recordForm': (context) => RecordFormPage(),
|
||||
'/recipeDetail': (context) => RecipeDetailPage(),
|
||||
'/momentForm': (context) => MomentFormPage(),
|
||||
'/moment': (context) => MomentPage()
|
||||
'/moment': (context) => MomentPage(),
|
||||
'/momentUser': (context) => MomentUserPage()
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,14 +30,16 @@ class SaTokenInfo {
|
||||
this.tag,
|
||||
});
|
||||
|
||||
factory SaTokenInfo.fromJson(Map<String, dynamic> json) => _$SaTokenInfoFromJson(json);
|
||||
factory SaTokenInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$SaTokenInfoFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$SaTokenInfoToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class User {
|
||||
int? id;
|
||||
String? username;
|
||||
String username;
|
||||
int? gender;
|
||||
String? phoneNumber;
|
||||
String? email;
|
||||
@@ -51,7 +53,7 @@ class User {
|
||||
|
||||
User({
|
||||
this.id,
|
||||
this.username,
|
||||
required this.username,
|
||||
this.gender,
|
||||
this.phoneNumber,
|
||||
this.email,
|
||||
@@ -65,7 +67,24 @@ class User {
|
||||
});
|
||||
|
||||
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$UserToJson(this);
|
||||
|
||||
static User getEmpty() {
|
||||
return User(
|
||||
username: '',
|
||||
gender: 0,
|
||||
phoneNumber: '',
|
||||
email: '',
|
||||
birthDate: null,
|
||||
avatar: '',
|
||||
area: [],
|
||||
address: '',
|
||||
job: '',
|
||||
tags: [],
|
||||
description: '',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
@@ -75,6 +94,8 @@ class Session {
|
||||
|
||||
Session({required this.saToken, required this.userInfo});
|
||||
|
||||
factory Session.fromJson(Map<String, dynamic> json) => _$SessionFromJson(json);
|
||||
factory Session.fromJson(Map<String, dynamic> json) =>
|
||||
_$SessionFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$SessionToJson(this);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ Map<String, dynamic> _$SaTokenInfoToJson(SaTokenInfo instance) =>
|
||||
|
||||
User _$UserFromJson(Map<String, dynamic> json) => User(
|
||||
id: (json['id'] as num?)?.toInt(),
|
||||
username: json['username'] as String?,
|
||||
username: json['username'] as String,
|
||||
gender: (json['gender'] as num?)?.toInt(),
|
||||
phoneNumber: json['phoneNumber'] as String?,
|
||||
email: json['email'] as String?,
|
||||
|
||||
@@ -306,6 +306,26 @@ class FoodProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> queryMomentByUserId(int userId) async {
|
||||
if (isLoading) return;
|
||||
|
||||
try {
|
||||
isLoading = true;
|
||||
error = null;
|
||||
notifyListeners();
|
||||
|
||||
final result = await queryMomentListByUserIdApi(userId);
|
||||
momentList = result;
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
error = '加载数据失败: $e';
|
||||
debugPrint('加载数据失败: $e');
|
||||
} finally {
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadMoreMomentList() async {
|
||||
if (hasMore && !isLoading) {
|
||||
await queryMomentByPage(isRefresh: false);
|
||||
|
||||
28
lib/provider/user_provider.dart
Normal file
28
lib/provider/user_provider.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:food_hub_app/apis/user.dart';
|
||||
import 'package:food_hub_app/models/session.dart';
|
||||
|
||||
class UserProvider with ChangeNotifier {
|
||||
late User currentUser = User.getEmpty();
|
||||
bool isLoading = false;
|
||||
String error = '';
|
||||
|
||||
Future<void> refreshUser(int id) async {
|
||||
if (isLoading) return;
|
||||
|
||||
try {
|
||||
isLoading = true;
|
||||
error = '';
|
||||
notifyListeners();
|
||||
|
||||
final result = await queryUserApi(id);
|
||||
currentUser = result;
|
||||
} catch (e) {
|
||||
error = '加载数据失败: $e';
|
||||
debugPrint('加载数据失败: $e');
|
||||
} finally {
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class _HomePage extends State<HomePage> {
|
||||
);
|
||||
},
|
||||
),
|
||||
actions: [AppActions()],
|
||||
actions: [AppActions(pageIndex: _currentIndex)],
|
||||
),
|
||||
// backgroundColor: Color(0xFFF5F5F5),
|
||||
drawer: AppDrawer(),
|
||||
|
||||
@@ -63,6 +63,10 @@ class _LoginPage extends State<LoginPage> {
|
||||
SPUtil.set('token', token);
|
||||
}
|
||||
|
||||
void handleUserInfo(User user) {
|
||||
SPUtil.set('userId', user.id);
|
||||
}
|
||||
|
||||
void loginClick() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
@@ -78,6 +82,7 @@ class _LoginPage extends State<LoginPage> {
|
||||
ToastUtil.success('登录成功');
|
||||
handleRememberState();
|
||||
handleTokenState(session.saToken.tokenValue);
|
||||
handleUserInfo(session.userInfo);
|
||||
|
||||
LoadingDialog.hide(context);
|
||||
Navigator.pushNamed(context, '/home');
|
||||
|
||||
@@ -84,7 +84,7 @@ class _MomentPageState extends State<MomentPage> {
|
||||
itemCount: provider.momentList.length,
|
||||
separatorBuilder: (context, index) => SizedBox(height: 8),
|
||||
itemBuilder: (context, index) {
|
||||
return MomentCard(moment: provider.momentList[index]);
|
||||
return MomentCard(moment: provider.momentList[index], isUser: false);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class _MomentFormPageState extends State<MomentFormPage> {
|
||||
|
||||
return FormBuilderTextField(
|
||||
name: _contentField,
|
||||
initialValue: provider.momentFormItem.content,
|
||||
focusNode: _focusNode,
|
||||
maxLines: 5,
|
||||
minLines: 3,
|
||||
@@ -110,7 +111,7 @@ class _MomentFormPageState extends State<MomentFormPage> {
|
||||
_buildContentField(provider),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
buildFormLabel(context: context, text: '上传图片', isRequired: false),
|
||||
buildFormLabel(context: context, text: '上传图片(最多9张)', isRequired: false),
|
||||
const SizedBox(height: 8),
|
||||
_buildImageField(provider),
|
||||
const SizedBox(height: 8),
|
||||
@@ -218,7 +219,6 @@ class _MomentFormPageState extends State<MomentFormPage> {
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
),
|
||||
backgroundColor: const Color(0xFFF5F5F5),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
|
||||
64
lib/views/moment_user.dart
Normal file
64
lib/views/moment_user.dart
Normal file
@@ -0,0 +1,64 @@
|
||||
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)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,209 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_common/utils/date_utils.dart';
|
||||
import 'package:flutter_common/utils/sp_utils.dart';
|
||||
import 'package:flutter_common/widget/common_widget.dart';
|
||||
import 'package:flutter_common/widget/dialog_widget.dart';
|
||||
import 'package:food_hub_app/config/app_config.dart';
|
||||
import 'package:food_hub_app/models/session.dart';
|
||||
import 'package:food_hub_app/provider/user_provider.dart';
|
||||
import 'package:food_hub_app/widgets/common/index.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||||
|
||||
class ProfilePage extends StatefulWidget {
|
||||
const ProfilePage({super.key});
|
||||
|
||||
@override
|
||||
State<ProfilePage> createState() => _ProfilePage();
|
||||
State<ProfilePage> createState() => ProfilePageState();
|
||||
}
|
||||
|
||||
class _ProfilePage extends State<ProfilePage>{
|
||||
class ProfilePageState extends State<ProfilePage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// 初始化加载数据
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.read<UserProvider>().refreshUser(SPUtil.getInt('userId'));
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildAvatar(User user) {
|
||||
if (user.avatar!.isEmpty) {
|
||||
return TDAvatar(
|
||||
size: TDAvatarSize.large,
|
||||
type: TDAvatarType.customText,
|
||||
shape: TDAvatarShape.circle,
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
text: user.username.isNotEmpty ? user.username[0] : '?',
|
||||
);
|
||||
} else {
|
||||
return TDAvatar(
|
||||
size: TDAvatarSize.large,
|
||||
type: TDAvatarType.normal,
|
||||
fit: BoxFit.contain,
|
||||
avatarUrl: '${AppConfig.imageBaseUrl}/${user.avatar}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildInfoItem({required IconData icon, required String text}) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 16, color: colors.primary),
|
||||
const SizedBox(width: 6),
|
||||
Text(text),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFunctionButton({
|
||||
required IconData icon,
|
||||
required String text,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Icon(icon, color: colors.primary),
|
||||
title: Text(text),
|
||||
trailing: Icon(Icons.arrow_forward_ios, size: 16, color: colors.primary),
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBasicInfo(User user) {
|
||||
return CommonCard(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildAvatar(user),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
user.username,
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (user.tags != null && user.tags!.isNotEmpty)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children:
|
||||
user.tags!.map((tag) => buildTag(context, tag)).toList(),
|
||||
),
|
||||
if (user.tags != null && user.tags!.isNotEmpty)
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
if (user.area != null && user.area!.length >= 2)
|
||||
_buildInfoItem(
|
||||
icon: Icons.location_on,
|
||||
text: '${user.area![0]}-${user.area![1]}',
|
||||
),
|
||||
if (user.birthDate != null)
|
||||
_buildInfoItem(
|
||||
icon: Icons.cake,
|
||||
text: formatDate(user.birthDate!),
|
||||
),
|
||||
if (user.job != null && user.job!.isNotEmpty)
|
||||
_buildInfoItem(icon: Icons.work, text: user.job!),
|
||||
if (user.phoneNumber != null && user.phoneNumber!.isNotEmpty)
|
||||
_buildInfoItem(
|
||||
icon: Icons.phone_android,
|
||||
text: user.phoneNumber!,
|
||||
),
|
||||
if (user.email != null && user.email!.isNotEmpty)
|
||||
_buildInfoItem(icon: Icons.email, text: user.email!),
|
||||
],
|
||||
),
|
||||
if (user.description != null && user.description!.isNotEmpty)
|
||||
const SizedBox(height: 8),
|
||||
if (user.description != null && user.description!.isNotEmpty)
|
||||
Text(user.description!),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onTapMoment() {
|
||||
Navigator.pushNamed(context, '/momentUser');
|
||||
}
|
||||
|
||||
Widget _buildFunctionButtons() {
|
||||
return CommonCard(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildFunctionButton(
|
||||
icon: Icons.account_circle,
|
||||
text: '基本资料',
|
||||
onTap: () {
|
||||
// 跳转到编辑资料页面
|
||||
// LogUtils.i('点击编辑资料');
|
||||
},
|
||||
),
|
||||
const Divider(height: 1),
|
||||
_buildFunctionButton(
|
||||
icon: Icons.group_outlined,
|
||||
text: '朋友圈',
|
||||
onTap: _onTapMoment,
|
||||
),
|
||||
const Divider(height: 1),
|
||||
_buildFunctionButton(
|
||||
icon: Icons.favorite,
|
||||
text: '我的收藏',
|
||||
onTap: () {
|
||||
// 跳转到浏览历史页面
|
||||
// LogUtils.i('点击浏览历史');
|
||||
},
|
||||
),
|
||||
const Divider(height: 1),
|
||||
_buildFunctionButton(
|
||||
icon: Icons.lock,
|
||||
text: '更改密码',
|
||||
onTap: () {
|
||||
// 跳转到帮助与反馈页面
|
||||
// LogUtils.i('点击帮助与反馈');
|
||||
},
|
||||
),
|
||||
const Divider(height: 1),
|
||||
_buildFunctionButton(
|
||||
icon: Icons.exit_to_app,
|
||||
text: '退出登录',
|
||||
onTap: () {
|
||||
showConfirmDialog(context, '确认要退出吗?');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(UserProvider provider) {
|
||||
final user = provider.currentUser;
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(width: double.infinity, child: _buildBasicInfo(user)),
|
||||
const SizedBox(height: 16),
|
||||
_buildFunctionButtons(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Center(child: Text("个人主页"));
|
||||
final provider = context.watch<UserProvider>();
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
if (provider.isLoading)
|
||||
buildLoadingIndicator()
|
||||
else if (provider.error.isNotEmpty)
|
||||
Text(provider.error)
|
||||
else
|
||||
_buildContent(provider),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,16 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_common/widget/common_widget.dart';
|
||||
import 'package:food_hub_app/config/app_config.dart';
|
||||
import 'package:food_hub_app/models/moment.dart';
|
||||
import 'package:food_hub_app/provider/food_provider.dart';
|
||||
import 'package:food_hub_app/widgets/common/image.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||||
|
||||
class MomentCard extends StatelessWidget {
|
||||
final Moment moment;
|
||||
final bool isUser;
|
||||
|
||||
const MomentCard({super.key, required this.moment});
|
||||
const MomentCard({super.key, required this.moment, required this.isUser});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -32,7 +35,7 @@ class MomentCard extends StatelessWidget {
|
||||
const SizedBox(height: 10),
|
||||
_buildTime(),
|
||||
const SizedBox(height: 5),
|
||||
_buildActionButtons(),
|
||||
_buildActionButtons(context),
|
||||
if (moment.commentList!.isNotEmpty) ...[
|
||||
const SizedBox(height: 8),
|
||||
_buildCommentList(),
|
||||
@@ -52,7 +55,7 @@ class MomentCard extends StatelessWidget {
|
||||
size: TDAvatarSize.medium,
|
||||
type: TDAvatarType.customText,
|
||||
shape: TDAvatarShape.circle,
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
text: moment.username?[0],
|
||||
);
|
||||
} else {
|
||||
@@ -126,10 +129,31 @@ class MomentCard extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
void _onTapEdit(BuildContext context) {
|
||||
final provider = Provider.of<FoodProvider>(context, listen: false);
|
||||
provider.isEditing = true;
|
||||
provider.momentFormItem = moment;
|
||||
Navigator.pushNamed(context, '/momentForm');
|
||||
}
|
||||
|
||||
// 构建点赞和评论按钮
|
||||
Widget _buildActionButtons() {
|
||||
Widget _buildActionButtons(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
if (isUser)
|
||||
SizedBox(
|
||||
width: 42,
|
||||
height: 36,
|
||||
child: Stack(
|
||||
alignment: Alignment.bottomLeft,
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () => _onTapEdit(context),
|
||||
child: Icon(Icons.edit),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 42,
|
||||
height: 36,
|
||||
@@ -166,30 +190,6 @@ class MomentCard extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
// _buildActionButton(
|
||||
// icon: Icons.thumb_up_alt_outlined,
|
||||
// count: moment.likeList?.length ?? 0,
|
||||
// ),
|
||||
// const SizedBox(width: 20),
|
||||
// _buildActionButton(
|
||||
// icon: Icons.comment_outlined,
|
||||
// count: moment.commentList?.length ?? 0,
|
||||
// ),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// 构建带数字标记的动作按钮
|
||||
Widget _buildActionButton({required IconData icon, required int count}) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, color: Colors.grey[500], size: 18),
|
||||
const SizedBox(width: 4),
|
||||
if (count > 0)
|
||||
Text(
|
||||
count.toString(),
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey[500]),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user