| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:news_app/ui/topic/user_head_widget.dart';
- import '../../constant/color_res.dart';
- import '../../model/topic_item_model.dart';
- import '../../widget/auth_gesture_detector.dart';
- import '../../widget/my_txt.dart';
- /// @author: bo.zeng
- /// @email: cnhbwds@gmail.com
- /// @date: 2025 2025/4/9 16:00
- /// @description:
- class TopicItemWidget extends StatelessWidget {
- final TopicRecordModel? item;
- final bool isShow;
- final Function(String)? onLongTap;
- const TopicItemWidget(this.onLongTap,{super.key, required this.item, this.isShow = false});
- @override
- Widget build(BuildContext context) {
- return Container(
- padding: EdgeInsets.all(10.w),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(8.r),
- color: Colors.white,
- ),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- UserHeadWidget(
- nickname: item?.member?.nickname ?? "",
- avatar: item?.member?.avatar ?? "",
- time: "2025/1/1",
- ),
- SizedBox(height: 10.h),
- Text.rich(
- TextSpan(
- text: item?.topic?.content ?? "",
- style: TextStyle(color: Colors.blue, fontSize: 15.sp),
- children: [
- WidgetSpan(child: SizedBox(width: 5.w)),
- TextSpan(
- text: item?.content ?? "",
- style: TextStyle(fontSize: 15.sp, color: Colors.black),
- ),
- ],
- ),
- ),
- SizedBox(height: 10.h),
- if (item?.resourceList?.isNotEmpty == true)
- buildImageByResource(item?.resourceList),
- if (item?.resourceList?.isNotEmpty == true) SizedBox(height: 10.h),
- Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- if (isShow == true) AuthGestureDetector(
- onTap: () {
- onLongTap?.call(
- item?.contentId ?? '',
- );
- },
- child: Text(
- '举报',
- style: TextStyle(color: color333333, fontSize: 12.sp),
- ),
- ),
- if (isShow == true) SizedBox(width:15.w,),
- Icon(
- item?.isLiked == true ? Icons.favorite : Icons.favorite_border,
- color: item?.isLiked == true ? Colors.red : color666666,
- size: 14.w,
- ),
- myTxt(
- text: "${item?.likeNum ?? 0}",
- color: color666666,
- fontSize: 12.sp,
- ),
- SizedBox(width: 15.w),
- Icon(Icons.messenger_outline, color: color666666, size: 14.w),
- myTxt(
- text: "${item?.commentNum ?? 0}",
- color: color666666,
- fontSize: 12.sp,
- ),
- ],
- ),
- ],
- ),
- );
- }
- }
- Widget buildImageByResource(List<Resource>? resourceList) {
- if (resourceList == null || resourceList.isEmpty) {
- return const SizedBox.shrink();
- }
- Resource? imageResource = resourceList.firstWhere(
- (item) => item.type == "image",
- orElse: () => Resource(type: "", url: ""),
- );
- if (imageResource.url.isNotEmpty) {
- return CachedNetworkImage(
- imageUrl: imageResource.url,
- width: 211.h,
- height: 119.h,
- fit: BoxFit.cover,
- );
- } else {
- return const SizedBox.shrink();
- }
- }
|