feat:增加查询朋友朋友圈功能
This commit is contained in:
@@ -2,7 +2,7 @@ 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:food_hub_app/widgets/moment/list.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MomentUserPage extends StatefulWidget {
|
||||
@@ -23,16 +23,6 @@ class _MomentUserPageState extends State<MomentUserPage> {
|
||||
});
|
||||
}
|
||||
|
||||
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>();
|
||||
@@ -51,13 +41,15 @@ class _MomentUserPageState extends State<MomentUserPage> {
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
),
|
||||
backgroundColor: const Color(0xFFF5F5F5),
|
||||
body:
|
||||
provider.isLoading
|
||||
? buildLoadingIndicator()
|
||||
: Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: CommonCard(child: _buildMomentList(provider)),
|
||||
child: MomentList(
|
||||
momentList: provider.momentList,
|
||||
isUser: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
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/app_provider.dart';
|
||||
import 'package:food_hub_app/provider/user_provider.dart';
|
||||
import 'package:food_hub_app/widgets/common/index.dart';
|
||||
import 'package:food_hub_app/widgets/profile/basic_info.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||||
|
||||
class ProfilePage extends StatefulWidget {
|
||||
const ProfilePage({super.key});
|
||||
@@ -28,37 +25,6 @@ class ProfilePageState extends State<ProfilePage> {
|
||||
});
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -74,59 +40,6 @@ class ProfilePageState extends State<ProfilePage> {
|
||||
);
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
@@ -168,25 +81,51 @@ class ProfilePageState extends State<ProfilePage> {
|
||||
},
|
||||
),
|
||||
const Divider(height: 1),
|
||||
_buildFunctionButton(icon: Icons.message, text: '反馈意见', onTap: () {}),
|
||||
const Divider(height: 1),
|
||||
_buildFunctionButton(icon: Icons.refresh, text: '检查更新', onTap: () {}),
|
||||
const Divider(height: 1),
|
||||
_buildFunctionButton(
|
||||
icon: Icons.exit_to_app,
|
||||
text: '退出登录',
|
||||
onTap: () {
|
||||
showConfirmDialog(context, '确认要退出吗?');
|
||||
},
|
||||
onTap: _onTapLogout,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onTapLogout() async {
|
||||
final result = await showConfirmDialog(context, '确认要退出吗?');
|
||||
if (result == true) {
|
||||
SPUtil.remove('token');
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamed(context, '/login');
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildVersionInfo() {
|
||||
final provider = context.read<AppProvider>();
|
||||
|
||||
return Text(
|
||||
'版本 v${provider.fullVersion}',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(UserProvider provider) {
|
||||
final user = provider.currentUser;
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(width: double.infinity, child: _buildBasicInfo(user)),
|
||||
SizedBox(width: double.infinity, child: ProfileInfo(user: user)),
|
||||
const SizedBox(height: 16),
|
||||
_buildFunctionButtons(),
|
||||
const SizedBox(height: 8),
|
||||
_buildVersionInfo(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
117
lib/views/profile_user.dart
Normal file
117
lib/views/profile_user.dart
Normal file
@@ -0,0 +1,117 @@
|
||||
import 'package:flutter/material.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/models/session.dart';
|
||||
import 'package:food_hub_app/provider/app_provider.dart';
|
||||
import 'package:food_hub_app/provider/user_provider.dart';
|
||||
import 'package:food_hub_app/widgets/common/index.dart';
|
||||
import 'package:food_hub_app/widgets/moment/list.dart';
|
||||
import 'package:food_hub_app/widgets/profile/basic_info.dart';
|
||||
import 'package:food_hub_app/widgets/recipe/calendar.dart';
|
||||
import 'package:food_hub_app/widgets/recipe/list.dart';
|
||||
import 'package:food_hub_app/widgets/recipe/timeline.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
enum ProfileTab {
|
||||
moment('朋友圈'),
|
||||
recipe('菜谱');
|
||||
|
||||
final String label;
|
||||
|
||||
const ProfileTab(this.label);
|
||||
}
|
||||
|
||||
class ProfileUserPage extends StatefulWidget {
|
||||
const ProfileUserPage({super.key});
|
||||
|
||||
@override
|
||||
State<ProfileUserPage> createState() => ProfileUserPageState();
|
||||
}
|
||||
|
||||
class ProfileUserPageState extends State<ProfileUserPage> {
|
||||
late ProfileTab currentTab = ProfileTab.moment;
|
||||
|
||||
void _onTabChange(ProfileTab tab) {
|
||||
setState(() {
|
||||
currentTab = tab;
|
||||
});
|
||||
|
||||
// provider.onRecordTabChange();
|
||||
}
|
||||
|
||||
Widget _buildTabs({
|
||||
required BuildContext context,
|
||||
required ProfileTab currentTab,
|
||||
required ValueChanged<ProfileTab> onTabChanged,
|
||||
}) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: buildToggleSwitch(
|
||||
context: context,
|
||||
currentTab: currentTab,
|
||||
tabValues: ProfileTab.values,
|
||||
labels: ProfileTab.values.map((e) => e.label).toList(),
|
||||
onTabChanged: onTabChanged,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(UserProvider provider) {
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ProfileInfo(user: provider.currentUser),
|
||||
),
|
||||
_buildTabs(
|
||||
context: context,
|
||||
currentTab: currentTab,
|
||||
onTabChanged: (tab) => _onTabChange(tab),
|
||||
),
|
||||
Expanded(
|
||||
child: IndexedStack(
|
||||
index: currentTab.index,
|
||||
children: [
|
||||
MomentList(momentList: provider.momentList, isUser: false),
|
||||
Text('个人菜谱'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<UserProvider>();
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
'${provider.currentUser.username}的个人信息',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
backgroundColor: colors.primary,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Stack(
|
||||
children: [
|
||||
if (provider.isLoading)
|
||||
buildLoadingIndicator()
|
||||
else if (provider.error.isNotEmpty)
|
||||
Text(provider.error)
|
||||
else
|
||||
_buildContent(provider),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user