import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/community/community_view/community_comment.dart'; import 'package:huixiang/community/community_view/community_dynamic.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/comunity_comment.dart'; import 'package:huixiang/retrofit/data/member_comment_list.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/comment_menu.dart'; import 'package:huixiang/view_widget/login_tips_dialog.dart'; import 'package:huixiang/view_widget/tips_dialog.dart'; import 'package:huixiang/web/web_view/input_comment.dart'; import 'package:shared_preferences/shared_preferences.dart'; class CommunityDetails extends StatefulWidget { // final ComunityComment arguments; final Map arguments; CommunityDetails({this.arguments}); @override State createState() { return _CommunityDetails(); } } class _CommunityDetails extends State { double height = 0; double commentHeight = 60.h; List memberList = []; ApiService apiService; var commentFocus = FocusNode(); String hintText = S.current.liuxianinjingcaidepinglunba; bool isKeyBoardShow = false; @override void didChangeMetrics() { WidgetsBinding.instance.addPostFrameCallback((_) { if (MediaQuery.of(context).viewInsets.bottom == 0) { if (isKeyBoardShow) { FocusScope.of(context).requestFocus(FocusNode()); setState(() { hintText = S.current.liuxianinjingcaidepinglunba; isKeyBoardShow = false; }); } } else { setState(() { isKeyBoardShow = true; }); } }); } @override void initState() { super.initState(); SharedPreferences.getInstance().then((value) { apiService = ApiService( Dio(), context: context, token: value.getString("token"), ); }); } @override Widget build(BuildContext context) { return Column( children: [ Expanded( child: NestedScrollView( headerSliverBuilder: (context, position) { return [ SliverOverlapAbsorber( handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context), sliver: SliverAppBar( expandedHeight: (height == 0) ? 614 : height, pinned: true, backgroundColor: Colors.white, title: Text( "动态详情", style: TextStyle( color: Colors.black, fontSize: 18.sp, fontWeight: MyFontWeight.semi_bold, ), ), elevation: 0, leading: GestureDetector( onTap: () { Navigator.of(context).pop(); }, child: Container( alignment: Alignment.centerRight, margin: EdgeInsets.only(left: 10), padding: EdgeInsets.all(6), child: Icon( Icons.arrow_back_ios, color: Colors.black, size: 24, ), ), ), flexibleSpace: FlexibleSpaceBar( //Colors.white, background: Container( padding: EdgeInsets.only( top: MediaQuery.of(context).padding.top + kToolbarHeight, ), color: Colors.white, child: CommunityDynamic( widget.arguments["comment"], itemCount: 3, isDetails: true, heightFun: (height) { this.height = height + MediaQuery.of(context).padding.top + kToolbarHeight + 68; setState(() {}); }, ), ), collapseMode: CollapseMode.pin, ), bottom: PreferredSize( preferredSize: Size( MediaQuery.of(context).size.width, 46, ), child: Container( padding: EdgeInsets.all(16), margin: EdgeInsets.only(top: 16.h), color: Colors.white, child: Row( children: [ Text( S.of(context).pinglun_("1"), style: TextStyle( fontSize: 14, fontWeight: FontWeight.bold, color: Color(0xff1A1A1A), ), ), SizedBox( width: 16.w, ), Text( S.of(context).xihuan_("0"), style: TextStyle( fontSize: 14, fontWeight: FontWeight.bold, color: Color(0xff1A1A1A), ), ), ], ), ), ), ), ), ]; }, body: Container( height: MediaQuery.of(context).size.height - MediaQuery.of(context).padding.top + kToolbarHeight - 68, margin: EdgeInsets.only(top: 68 + 50 + kToolbarHeight), child: Column( children: [ if (memberList != null && memberList.length > 0) ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemCount: memberList != null ? memberList.length : 0, scrollDirection: Axis.vertical, itemBuilder: (context, position) { return Material( color: Colors.white, child: InkWell( onTap: () { showPressMenu(memberList[position].createUser, memberList[position]); }, child: CommunityComment( memberList[position], _queryCommentLike, ), ), ); }, ), if (memberList != null && memberList.length > 0) Container( height: commentHeight, decoration: BoxDecoration( color: Color(0xFFF2F2F2), boxShadow: [ BoxShadow( color: Colors.black.withAlpha(12), offset: Offset(0, 2), blurRadius: 14, spreadRadius: 0, ), ], ), alignment: Alignment.topCenter, padding: EdgeInsets.only(top: 22.h), child: Text( S.of(context).yixiansquanbupinglun, style: TextStyle( fontSize: 12, color: Color(0xff353535), ), ), ), if (memberList == null || memberList.length == 0) Container( width: double.infinity, alignment: Alignment.topCenter, padding: EdgeInsets.all(22.h), child: Text( S.of(context).zanwupinglun, style: TextStyle( fontSize: 12, fontWeight: FontWeight.bold, color: Color(0xFFA0A0A0), ), ), ), ], ), ), ), flex: 1, ), /// 富文本评论的输入框 InputComment( inputKey, hintText, isKeyBoardShow, commentFocus, commentTextController, _toComment, _queryMemberComment, _queryInformationLikes, ), ], ); } //给文章/活动点赞 _queryInformationLikes() async { BaseData baseData = await apiService.informationLikes(""); if (baseData != null && baseData.isSuccess) { // commentKey.currentState.setState(() {}); } else { SmartDialog.showToast(baseData.msg, alignment: Alignment.center); } } //发布评论 _queryMemberComment(String content) async { // BaseData baseData = await apiService.memberComment({ // "content": content, // "parentId": parenId, // "relationalId": // widget.arguments["activityId"] ?? widget.arguments["articleId"], // "relationalType": 1 // }).catchError((error) {}); // if (baseData != null && baseData.isSuccess) { // commentKey.currentState.initState(); // commentTextController.text = ""; // _toComment(); // } } ///滑动到评论列表 _toComment() { // if (commentKey.currentContext == null) return; // RenderBox firstRenderBox = commentKey.currentContext.findRenderObject(); // Offset first = firstRenderBox.localToGlobal(Offset.zero); // scrollController.animateTo(first.dy + scrollController.offset - // (kToolbarHeight + MediaQuery.of(context).padding.top), // duration: Duration(milliseconds: 300), // curve: Curves.easeIn); } final GlobalKey inputKey = GlobalKey(); final TextEditingController commentTextController = TextEditingController(); contentHeight() { double contentHeight = MediaQuery.of(context).size.height - kToolbarHeight - MediaQuery.of(context).padding.top - 160.h; if ((contentHeight - 60.h) > (128.h * memberList.length)) { commentHeight = contentHeight - (128.h * memberList.length); } } showPressMenu(String userId, memberComment) { if (isKeyBoardShow) { FocusScope.of(context).requestFocus(FocusNode()); return; } SharedPreferences.getInstance().then((value) { SmartDialog.show( widget: CommentMenu( (type) { SmartDialog.dismiss(); if (type == "huifu") { _reply(memberComment); } else if (type == "shanchu") { _delCommentTips(); } }, isSelf: userId == value.getString("userId"), ), alignmentTemp: Alignment.bottomCenter, isUseAnimationTemp: true, animationDurationTemp: Duration(milliseconds: 300), ); }); } ///删除评论的提示 _delCommentTips() { SmartDialog.show(widget: Tips(() { delComment(); })); } ///删除评论 delComment() async { BaseData baseData = await apiService.delComment(""); if (baseData != null && baseData.isSuccess) { // commentKey.currentState.initState(); } } ///评论 回复 _reply(memberComment) { FocusScope.of(context).requestFocus(commentFocus); // parenId = memberComment.id; hintText = S.of(context).huifu_("${memberComment.username}"); } //评论点赞 _queryCommentLike(String id) async { SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); String token = sharedPreferences.getString("token"); if (token == null || token == "") { LoginTipsDialog().show(context); return; } BaseData baseData = await apiService.commentLike(id).catchError((error) {}); if (baseData != null && baseData.isSuccess) { memberList.forEach((element) { if (element.id == id) { if (element.liked) { element.likes -= 1; element.liked = false; } else { element.likes += 1; element.liked = true; } } }); } } }