You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

297 lines
10 KiB

3 years ago
import 'package:dio/dio.dart';
3 years ago
import 'package:flutter/material.dart';
3 years ago
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
3 years ago
import 'package:huixiang/retrofit/data/comunity_comment.dart';
3 years ago
import 'package:huixiang/retrofit/retrofit_api.dart';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
3 years ago
import 'package:huixiang/view_widget/custom_image.dart';
3 years ago
import 'package:huixiang/view_widget/icon_text.dart';
import 'package:huixiang/view_widget/round_button.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
3 years ago
import 'package:shared_preferences/shared_preferences.dart';
3 years ago
class CommunityDynamic extends StatefulWidget {
final int itemCount;
final Function(double height) heightFun;
3 years ago
final bool isDetails;
3 years ago
final int commentType;
3 years ago
final ComunityComment comment;
3 years ago
3 years ago
CommunityDynamic(
3 years ago
this.comment,
this.commentType,{
3 years ago
Key key,
this.itemCount = 9,
this.heightFun,
this.isDetails = false,
}) : super(key: key);
@override
State<StatefulWidget> createState() {
return _CommunityDynamic();
}
}
class _CommunityDynamic extends State<CommunityDynamic> {
GlobalKey globalKey = GlobalKey();
double height = 0;
3 years ago
ApiService apiService;
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) => {
apiService = ApiService(Dio(),
context: context, token: value.getString('token')),
});
}
///关注/取关会员
_vipFollow(followId) async {
BaseData baseData = await apiService.follow(followId);
if (baseData != null && baseData.isSuccess) {
SmartDialog.showToast("关注成功");
}
}
3 years ago
@override
Widget build(BuildContext context) {
return Column(
children: [
Container(
3 years ago
key: globalKey,
3 years ago
alignment: Alignment.topCenter,
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Color(0x08000000),
offset: Offset(0, 1),
blurRadius: 8,
spreadRadius: 0,
),
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
height: 44,
child: Row(
children: [
3 years ago
MImage(
widget.comment != null ? widget.comment.memberInfo.avatar : "",
width: 44,
height: 44,
isCircle: true,
fit: BoxFit.cover,
errorSrc: "assets/image/default_1.png",
fadeSrc: "assets/image/default_1.png",
3 years ago
),
SizedBox(
width: 8,
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
3 years ago
widget.comment != null ? widget.comment.memberInfo.nickname : "",
3 years ago
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.medium,
color: Color(0xFF1A1A1A),
),
),
Text(
3 years ago
widget.comment != null ? widget.comment.createTime : "",
3 years ago
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Color(0xFF808080),
),
),
],
),
],
),
),
3 years ago
GestureDetector(
onTap: (){
setState(() {
if(widget.commentType == 0){
widget.comment.selfFollow = !(widget.comment.selfFollow??false);
_vipFollow(widget.comment.memberInfo.mid);
}else{
SmartDialog.showToast("删除成功", alignment: Alignment.center);
}
});
},
child: (widget.commentType == 0)?RoundButton(
padding: EdgeInsets.symmetric(
horizontal: 8,
vertical: 3,
),
backgroup: (widget.comment.selfFollow??false) ? Color(0xFFE6E6E6) : Color(0xFF32A060),
textColor: (widget.comment.selfFollow??false) ? Color(0xFF808080):Colors.white ,
text:(widget.comment.selfFollow??false) ? "已关注":"关注",
radius: 20,
icons: Icon(
(widget.comment.selfFollow??false) ? Icons.check: Icons.add,
color:(widget.comment.selfFollow??false) ? Color(0xFF808080):Colors.white ,
size: 14,
),
):Icon(
Icons.close,
color:Colors.black,
size: 16,
3 years ago
),
),
],
),
SizedBox(
height: 12.h,
),
Text(
3 years ago
widget.comment.subject ?? "",
3 years ago
maxLines: 5,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Color(0xFF1A1A1A),
fontWeight: MyFontWeight.regular,
fontSize: 14.sp,
),
),
3 years ago
buildMedia(widget.comment.subjectInfo),
3 years ago
if (!widget.isDetails)
SizedBox(
height: 12.h,
),
if (!widget.isDetails)
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
IconText(
3 years ago
"${widget.comment.viewers ?? 0}",
3 years ago
space: 4.w,
leftImage: "assets/svg/liulanliang.svg",
iconSize: 16,
),
IconText(
3 years ago
"${widget.comment.comments ?? 0}",
3 years ago
space: 4.w,
leftImage: "assets/svg/pinglun.svg",
iconSize: 16,
),
IconText(
3 years ago
"${widget.comment.likes ?? 0}",
3 years ago
space: 4.w,
leftImage: "assets/svg/xihuan.svg",
iconSize: 16,
),
],
),
],
),
),
Container(
height: 16,
color: Color(0xFFF7F7F7),
)
],
);
}
3 years ago
///动态内容
3 years ago
Widget buildMedia(SubjectInfo subjectInfo) {
if (subjectInfo == null) {
return Container();
}
Widget widget = Container();
if (subjectInfo.type == "image" && subjectInfo.images.length > 0) {
if (subjectInfo.images.length == 1) {
widget = Container(
child: MImage(
subjectInfo.images[0],
fit: BoxFit.cover,
width: MediaQuery.of(context).size.width / 2,
height: MediaQuery.of(context).size.width / 2,
errorSrc: "assets/image/default_2_1.png",
fadeSrc: "assets/image/default_2_1.png",
),
);
} else {
widget = GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: (subjectInfo.images.length == 2 ||
subjectInfo.images.length == 4)
? 2
: 3,
crossAxisSpacing: 12.w,
mainAxisSpacing: 12.w,
childAspectRatio: 1,
),
padding: EdgeInsets.zero,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, position) {
return Container(
child: MImage(
subjectInfo.images[0],
fit: BoxFit.cover,
aspectRatio: 1,
errorSrc: "assets/image/default_2_1.png",
fadeSrc: "assets/image/default_2_1.png",
),
);
},
itemCount: subjectInfo.images.length,
);
}
} else if (subjectInfo.type == "video" &&
subjectInfo.video != null &&
subjectInfo.video != "") {
widget = Container(
width: MediaQuery.of(context).size.width - 32,
height: MediaQuery.of(context).size.width / 2,
color: Colors.blue.withAlpha(123),
);
}
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: 16.h,
),
widget,
],
);
}
3 years ago
@override
void didChangeDependencies() {
3 years ago
if (widget.heightFun != null)
WidgetsBinding.instance.addPostFrameCallback(_getContainerHeight);
3 years ago
super.didChangeDependencies();
}
_getContainerHeight(_) {
3 years ago
if (globalKey.currentContext != null)
height = globalKey.currentContext.size.height;
if (widget.heightFun != null) widget.heightFun(height);
3 years ago
print("height: $height");
}
}