feat:重构模块
This commit is contained in:
@@ -7,7 +7,6 @@ import 'package:food_hub_app/provider/food_provider.dart';
|
||||
import 'package:food_hub_app/provider/user_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 StatefulWidget {
|
||||
final Moment moment;
|
||||
@@ -26,21 +25,24 @@ class MomentCardState extends State<MomentCard> {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
InkWell(onTap: () => _onTapUser(context), child: _buildAvatar()),
|
||||
InkWell(
|
||||
onTap: () => _onTapUser(context),
|
||||
child: _buildAvatar(context),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildNickname(),
|
||||
_buildNickname(context),
|
||||
const SizedBox(height: 5),
|
||||
_buildContent(),
|
||||
_buildContent(context),
|
||||
if (widget.moment.imageList.isNotEmpty) ...[
|
||||
const SizedBox(height: 8),
|
||||
_buildPostImages(),
|
||||
],
|
||||
const SizedBox(height: 10),
|
||||
_buildTime(),
|
||||
_buildTime(context),
|
||||
const SizedBox(height: 5),
|
||||
_buildActionButtons(),
|
||||
if (widget.moment.commentList!.isNotEmpty) ...[
|
||||
@@ -69,38 +71,35 @@ class MomentCardState extends State<MomentCard> {
|
||||
}
|
||||
|
||||
// 构建头像组件
|
||||
Widget _buildAvatar() {
|
||||
Widget _buildAvatar(BuildContext context) {
|
||||
if (widget.moment.avatar!.isEmpty) {
|
||||
return TDAvatar(
|
||||
size: TDAvatarSize.medium,
|
||||
type: TDAvatarType.customText,
|
||||
shape: TDAvatarShape.circle,
|
||||
return CircleAvatar(
|
||||
radius: 18,
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
text: widget.moment.username?[0],
|
||||
foregroundColor: Theme.of(context).colorScheme.surface,
|
||||
child: Text(widget.moment.username![0], style: TextStyle(fontSize: 14)),
|
||||
);
|
||||
} else {
|
||||
return TDAvatar(
|
||||
size: TDAvatarSize.medium,
|
||||
type: TDAvatarType.normal,
|
||||
fit: BoxFit.contain,
|
||||
avatarUrl: '${AppConfig.imageBaseUrl}/${widget.moment.avatar}',
|
||||
return CircleAvatar(
|
||||
radius: 18,
|
||||
backgroundImage: NetworkImage('${AppConfig.imageBaseUrl}/${widget.moment.avatar}')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 构建昵称组件
|
||||
Widget _buildNickname() {
|
||||
Widget _buildNickname(BuildContext context) {
|
||||
return Text(
|
||||
widget.moment.username ?? "",
|
||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
);
|
||||
}
|
||||
|
||||
// 构建内容组件
|
||||
Widget _buildContent() {
|
||||
Widget _buildContent(BuildContext context) {
|
||||
return Text(
|
||||
widget.moment.content,
|
||||
style: const TextStyle(fontSize: 15, height: 1.3),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -142,10 +141,10 @@ class MomentCardState extends State<MomentCard> {
|
||||
}
|
||||
|
||||
// 构建时间组件
|
||||
Widget _buildTime() {
|
||||
Widget _buildTime(BuildContext context) {
|
||||
return Text(
|
||||
widget.moment.date ?? "",
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey[500]),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -178,14 +177,14 @@ class MomentCardState extends State<MomentCard> {
|
||||
alignment: Alignment.bottomLeft,
|
||||
children: [
|
||||
Icon(Icons.thumb_up_alt_outlined),
|
||||
Positioned(
|
||||
left: 20,
|
||||
bottom: 15,
|
||||
child: TDBadge(
|
||||
TDBadgeType.message,
|
||||
count: (widget.moment.likeList?.length ?? 0).toString(),
|
||||
),
|
||||
),
|
||||
// Positioned(
|
||||
// left: 20,
|
||||
// bottom: 15,
|
||||
// child: TDBadge(
|
||||
// TDBadgeType.message,
|
||||
// count: (widget.moment.likeList?.length ?? 0).toString(),
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -196,14 +195,14 @@ class MomentCardState extends State<MomentCard> {
|
||||
alignment: Alignment.bottomLeft,
|
||||
children: [
|
||||
Icon(Icons.comment_outlined),
|
||||
Positioned(
|
||||
left: 20,
|
||||
bottom: 15,
|
||||
child: TDBadge(
|
||||
TDBadgeType.message,
|
||||
count: (widget.moment.commentList?.length ?? 0).toString(),
|
||||
),
|
||||
),
|
||||
// Positioned(
|
||||
// left: 20,
|
||||
// bottom: 15,
|
||||
// child: TDBadge(
|
||||
// TDBadgeType.message,
|
||||
// count: (widget.moment.commentList?.length ?? 0).toString(),
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user