Browse Source

safety

master
fmk 3 years ago
parent
commit
aea6451cec
  1. 165
      lib/community/community_details.dart
  2. 5
      lib/web/web_page.dart
  3. 15
      lib/web/web_view/comment_list.dart

165
lib/community/community_details.dart

@ -32,8 +32,7 @@ class CommunityDetails extends StatefulWidget {
} }
} }
class _CommunityDetails extends State<CommunityDetails> class _CommunityDetails extends State<CommunityDetails> with WidgetsBindingObserver {
with WidgetsBindingObserver {
double height = 0; double height = 0;
double commentHeight = 60.h; double commentHeight = 60.h;
ComunityComment comunity; ComunityComment comunity;
@ -54,7 +53,10 @@ class _CommunityDetails extends State<CommunityDetails>
void didChangeMetrics() { void didChangeMetrics() {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return; if (!mounted) return;
if (MediaQuery.of(context).viewInsets.bottom == 0) { if (MediaQuery
.of(context)
.viewInsets
.bottom == 0) {
if (isKeyBoardShow) { if (isKeyBoardShow) {
FocusScope.of(context).requestFocus(FocusNode()); FocusScope.of(context).requestFocus(FocusNode());
if (mounted) if (mounted)
@ -91,8 +93,10 @@ class _CommunityDetails extends State<CommunityDetails>
context: context, context: context,
token: value.getString("token"), token: value.getString("token"),
); );
BaseData<Article> baseData = BaseData<Article> baseData = await apiService.informationInfo(comunity.id)
await apiService.informationInfo(comunity.id).catchError((onError) {}); .catchError((onError) {
debugPrint(onError);
});
if (baseData != null && baseData.isSuccess) {} if (baseData != null && baseData.isSuccess) {}
} }
@ -125,75 +129,24 @@ class _CommunityDetails extends State<CommunityDetails>
isDetails: true, isDetails: true,
heightFun: (height) { heightFun: (height) {
this.height = height + this.height = height +
MediaQuery.of(context).padding.top + MediaQuery
.of(context)
.padding
.top +
kToolbarHeight + kToolbarHeight +
24; 24;
if (mounted) setState(() {}); if (mounted) setState(() {});
}, },
), ),
// CommentList( CommentList(
// commentKey, commentKey,
// widget.arguments, "${comunity?.likes ?? comunity?.likes ?? "0"}",
// activity, comunity.id,
// article, isKeyBoardShow,
// isKeyBoardShow, _reply,
// _reply, _delCommentTips,
// _delCommentTips, 12.sp,
// 12.sp,
// )
Container(
padding: EdgeInsets.all(16),
color: Colors.white,
child: Row(
children: [
Text(
S.of(context).pinglun_(commentTotal.toString()),
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Color(0xff1A1A1A),
),
),
SizedBox(
width: 16.w,
),
Text(
S.of(context).xihuan_(
"${comunity?.likes ?? comunity?.likes ?? "0"}"),
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Color(0xff1A1A1A),
),
),
],
),
), ),
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,
(memberList.length - 1 == position) ? 1 : 0,
),
),
);
},
),
if (memberList == null || memberList.length == 0) if (memberList == null || memberList.length == 0)
Container( Container(
width: double.infinity, width: double.infinity,
@ -201,7 +154,9 @@ class _CommunityDetails extends State<CommunityDetails>
margin: EdgeInsets.only(top: 40), margin: EdgeInsets.only(top: 40),
padding: EdgeInsets.all(22.h), padding: EdgeInsets.all(22.h),
child: Text( child: Text(
S.of(context).zanwupinglun, S
.of(context)
.zanwupinglun,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
@ -237,7 +192,7 @@ class _CommunityDetails extends State<CommunityDetails>
_queryInformationLikes() async { _queryInformationLikes() async {
BaseData baseData = await apiService.informationLikes(comunity.id); BaseData baseData = await apiService.informationLikes(comunity.id);
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
// commentKey.currentState.setState(() {}); commentKey.currentState.setState(() {});
setState(() { setState(() {
if (comunity.selfLike ?? false) if (comunity.selfLike ?? false)
comunity.likes -= 1; comunity.likes -= 1;
@ -259,7 +214,7 @@ class _CommunityDetails extends State<CommunityDetails>
"relationalType": 1 "relationalType": 1
}).catchError((error) {}); }).catchError((error) {});
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
// commentKey.currentState.initState(); commentKey.currentState.initState();
commentTextController.text = ""; commentTextController.text = "";
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
_queryMemberCommentList(); _queryMemberCommentList();
@ -274,7 +229,10 @@ class _CommunityDetails extends State<CommunityDetails>
scrollController.animateTo( scrollController.animateTo(
first.dy + first.dy +
scrollController.offset - scrollController.offset -
(kToolbarHeight + MediaQuery.of(context).padding.top), (kToolbarHeight + MediaQuery
.of(context)
.padding
.top),
duration: Duration(milliseconds: 300), duration: Duration(milliseconds: 300),
curve: Curves.easeIn, curve: Curves.easeIn,
); );
@ -284,40 +242,21 @@ class _CommunityDetails extends State<CommunityDetails>
final TextEditingController commentTextController = TextEditingController(); final TextEditingController commentTextController = TextEditingController();
contentHeight() { contentHeight() {
double contentHeight = MediaQuery.of(context).size.height - double contentHeight = MediaQuery
.of(context)
.size
.height -
kToolbarHeight - kToolbarHeight -
MediaQuery.of(context).padding.top - MediaQuery
.of(context)
.padding
.top -
160.h; 160.h;
if ((contentHeight - 60.h) > (128.h * memberList.length)) { if ((contentHeight - 60.h) > (128.h * memberList.length)) {
commentHeight = contentHeight - (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() { _delCommentTips() {
SmartDialog.show(widget: Tips(() { SmartDialog.show(widget: Tips(() {
@ -329,7 +268,7 @@ class _CommunityDetails extends State<CommunityDetails>
delComment() async { delComment() async {
BaseData baseData = await apiService.delComment(""); BaseData baseData = await apiService.delComment("");
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
// commentKey.currentState.initState(); commentKey.currentState.initState();
} }
} }
@ -340,30 +279,6 @@ class _CommunityDetails extends State<CommunityDetails>
hintText = S.of(context).huifu_("${memberComment.username}"); 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;
}
}
});
}
}
/// ///
_queryMemberCommentList() async { _queryMemberCommentList() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
@ -375,7 +290,7 @@ class _CommunityDetails extends State<CommunityDetails>
showLoading: false, showLoading: false,
); );
BaseData<PageInfo<MemberCommentList>> baseData = BaseData<PageInfo<MemberCommentList>> baseData =
await apiService.memberCommentList({ await apiService.memberCommentList({
"pageNum": 1, "pageNum": 1,
"pageSize": 100, "pageSize": 100,
"relationalId": comunity.id, "relationalId": comunity.id,

5
lib/web/web_page.dart

@ -271,9 +271,8 @@ class _WebPage extends State<WebPage> with WidgetsBindingObserver {
/// ///
CommentList( CommentList(
commentKey, commentKey,
widget.arguments, article?.likes ?? activity?.likes ?? "0",
activity, article?.id ?? activity?.id,
article,
isKeyBoardShow, isKeyBoardShow,
_reply, _reply,
_delCommentTips, _delCommentTips,

15
lib/web/web_view/comment_list.dart

@ -16,15 +16,15 @@ import 'package:like_button/like_button.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
class CommentList extends StatefulWidget { class CommentList extends StatefulWidget {
final Map arguments;
final Activity activity;
final Article article;
final bool isKeyBoardShow; final bool isKeyBoardShow;
final Function reply; final Function reply;
final Function delCommentTips; final Function delCommentTips;
final double fontSize; final double fontSize;
final String relationalId;
final String like;
CommentList(Key key, this.arguments, this.activity, this.article, CommentList(Key key, this.like, this.relationalId,
this.isKeyBoardShow, this.reply, this.delCommentTips, this.fontSize) this.isKeyBoardShow, this.reply, this.delCommentTips, this.fontSize)
: super(key: key); : super(key: key);
@ -57,6 +57,7 @@ class CommentListState extends State<CommentList> {
} else { } else {
element.likes += 1; element.likes += 1;
element.liked = true; element.liked = true;
} }
} }
}); });
@ -105,8 +106,7 @@ class CommentListState extends State<CommentList> {
width: 16.w, width: 16.w,
), ),
Text( Text(
S.of(context).xihuan_( S.of(context).xihuan_("${widget.like ?? "0"}"),
"${widget.article?.likes ?? widget.activity?.likes ?? "0"}"),
style: TextStyle( style: TextStyle(
fontSize: widget.fontSize + 4, fontSize: widget.fontSize + 4,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
@ -209,8 +209,7 @@ class CommentListState extends State<CommentList> {
await apiService.memberCommentList({ await apiService.memberCommentList({
"pageNum": 1, "pageNum": 1,
"pageSize": 100, "pageSize": 100,
"relationalId": "relationalId": widget.relationalId,
widget.arguments["activityId"] ?? widget.arguments["articleId"],
"relationalType": 1, "relationalType": 1,
}).catchError((error) {}); }).catchError((error) {});
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {

Loading…
Cancel
Save