fmk
3 years ago
32 changed files with 1432 additions and 225 deletions
@ -0,0 +1,136 @@
|
||||
import 'package:dio/dio.dart'; |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:huixiang/retrofit/data/base_data.dart'; |
||||
import 'package:huixiang/retrofit/data/comunity_comment.dart'; |
||||
import 'package:huixiang/retrofit/data/page.dart'; |
||||
import 'package:huixiang/retrofit/retrofit_api.dart'; |
||||
import 'package:huixiang/view_widget/classic_header.dart'; |
||||
import 'package:huixiang/view_widget/my_footer.dart'; |
||||
import 'package:pull_to_refresh/pull_to_refresh.dart'; |
||||
import 'package:shared_preferences/shared_preferences.dart'; |
||||
|
||||
import 'community_list.dart'; |
||||
|
||||
class CommunityChildList extends StatefulWidget { |
||||
final String typeStr; |
||||
|
||||
CommunityChildList(this.typeStr); |
||||
|
||||
@override |
||||
State<StatefulWidget> createState() { |
||||
return _CommunityChildList(); |
||||
} |
||||
} |
||||
|
||||
class _CommunityChildList extends State<CommunityChildList> { |
||||
RefreshController refreshController = RefreshController(); |
||||
final ScrollController scrollController = ScrollController(); |
||||
ApiService apiService; |
||||
int pageNum = 1; |
||||
String userId; |
||||
bool isLoadMore = false; |
||||
|
||||
List<ComunityComment> comments = []; |
||||
|
||||
@override |
||||
void initState() { |
||||
super.initState(); |
||||
_onRefresh(); |
||||
} |
||||
|
||||
_onRefresh() async { |
||||
setState(() {}); |
||||
} |
||||
|
||||
///动态列表 |
||||
queryCommunity() async { |
||||
if (apiService == null) { |
||||
SharedPreferences value = await SharedPreferences.getInstance(); |
||||
userId = value.getString('userId'); |
||||
apiService = ApiService( |
||||
Dio(), |
||||
context: context, |
||||
token: value.getString("token"), |
||||
); |
||||
} |
||||
if(isLoadMore){ |
||||
pageNum += 1; |
||||
isLoadMore = false; |
||||
}else pageNum = 1; |
||||
BaseData<PageInfo<ComunityComment>> baseData = await apiService.trendList({ |
||||
"onlyFollow": widget.typeStr == "关注" ? true : false, |
||||
"onlyMe": false, |
||||
"pageNum": pageNum, |
||||
"pageSize": 10, |
||||
"searchKey": "" |
||||
}).catchError((error) { |
||||
refreshController.refreshFailed(); |
||||
refreshController.loadFailed(); |
||||
}); |
||||
|
||||
refreshController.refreshCompleted(); |
||||
refreshController.loadComplete(); |
||||
if (baseData.isSuccess) { |
||||
if (pageNum == 1) { |
||||
comments.clear(); |
||||
} |
||||
comments.addAll(baseData.data.list); |
||||
// comments.sort((a,b)=>b.createTime.compareTo(a.createTime)); |
||||
// print("comments: ${comments.length}"); |
||||
if (int.tryParse(baseData.data.total) < (pageNum * 10)) { |
||||
refreshController.loadNoData(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
return FutureBuilder( |
||||
future: queryCommunity(), |
||||
builder: (context, position) { |
||||
return SmartRefresher( |
||||
controller: refreshController, |
||||
enablePullDown: true, |
||||
enablePullUp: true, |
||||
physics: BouncingScrollPhysics(), |
||||
header: MyHeader(), |
||||
footer: CustomFooter( |
||||
builder: (context, mode) { |
||||
return MyFooter(mode); |
||||
}, |
||||
), |
||||
onRefresh: _onRefresh, |
||||
onLoading: () { |
||||
isLoadMore = true; |
||||
setState(() {}); |
||||
}, |
||||
scrollController: scrollController, |
||||
child: Container( |
||||
child: SingleChildScrollView( |
||||
physics: BouncingScrollPhysics(), |
||||
child: Container( |
||||
// color: Color(0xFFF7F7F7), |
||||
// margin: EdgeInsets.only(top: 16.h), |
||||
child: Column( |
||||
children: [ |
||||
CommunityList( |
||||
comments, |
||||
userId, |
||||
0, |
||||
isList: true, |
||||
exitFull: () { |
||||
setState(() { |
||||
_onRefresh(); |
||||
}); |
||||
}, |
||||
), |
||||
], |
||||
), |
||||
), |
||||
), |
||||
), |
||||
); |
||||
}, |
||||
); |
||||
} |
||||
} |
@ -0,0 +1,489 @@
|
||||
import 'package:dio/dio.dart'; |
||||
import 'package:flutter/cupertino.dart'; |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
||||
import 'package:huixiang/community/photo_view_gallery_screen.dart'; |
||||
import 'package:huixiang/retrofit/data/base_data.dart'; |
||||
import 'package:huixiang/retrofit/data/comunity_comment.dart'; |
||||
import 'package:huixiang/retrofit/retrofit_api.dart'; |
||||
import 'package:huixiang/utils/font_weight.dart'; |
||||
import 'package:huixiang/view_widget/border_text.dart'; |
||||
import 'package:huixiang/view_widget/custom_image.dart'; |
||||
import 'package:huixiang/view_widget/icon_text.dart'; |
||||
import 'package:huixiang/view_widget/round_button.dart'; |
||||
import 'package:shared_preferences/shared_preferences.dart'; |
||||
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
||||
|
||||
class CommunityList extends StatefulWidget { |
||||
final List<ComunityComment> comments; |
||||
final String userId; |
||||
final int commentType; |
||||
final bool isList; |
||||
final Function exitFull; |
||||
|
||||
CommunityList( |
||||
this.comments, |
||||
this.userId, |
||||
this.commentType,{ |
||||
this.isList = false, |
||||
this.exitFull, |
||||
} |
||||
|
||||
); |
||||
|
||||
@override |
||||
State<StatefulWidget> createState() { |
||||
return _CommunityList(); |
||||
} |
||||
} |
||||
|
||||
class _CommunityList extends State<CommunityList> { |
||||
ApiService apiService; |
||||
|
||||
@override |
||||
void initState() { |
||||
super.initState(); |
||||
|
||||
SharedPreferences.getInstance().then((value) => { |
||||
apiService = ApiService(Dio(), |
||||
context: context, token: value.getString("token")), |
||||
}); |
||||
} |
||||
|
||||
///关注/取关会员 |
||||
_vipFollow(followId, isFollow) async { |
||||
BaseData baseData = await apiService.follow(followId); |
||||
if (baseData != null && baseData.isSuccess) { |
||||
widget.exitFull(); |
||||
SmartDialog.showToast(isFollow ? "关注成功" : "取关成功", |
||||
alignment: Alignment.center); |
||||
setState(() {}); |
||||
} else { |
||||
SmartDialog.showToast(baseData.msg, alignment: Alignment.center); |
||||
} |
||||
} |
||||
|
||||
///删除动态 |
||||
_deleteDynamic(id) async { |
||||
BaseData baseData = await apiService.deleteTrend(id); |
||||
if (baseData != null && baseData.isSuccess) { |
||||
widget.exitFull(); |
||||
SmartDialog.showToast("删除成功", alignment: Alignment.center); |
||||
setState(() {}); |
||||
} else { |
||||
// SmartDialog.showToast(baseData.msg, alignment: Alignment.center); |
||||
} |
||||
} |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
return Container( |
||||
child: Column( |
||||
crossAxisAlignment: CrossAxisAlignment.start, |
||||
mainAxisAlignment: MainAxisAlignment.spaceAround, |
||||
children: [ |
||||
ListView.builder( |
||||
padding: EdgeInsets.zero, |
||||
itemCount: widget.comments.length, |
||||
scrollDirection: Axis.vertical, |
||||
shrinkWrap: true, |
||||
physics: NeverScrollableScrollPhysics(), |
||||
itemBuilder: (context, position) { |
||||
return GestureDetector( |
||||
onTap: () { |
||||
Navigator.of(context) |
||||
.pushNamed('/router/new_community_details', arguments: { |
||||
"commentsId": widget.comments[position].id, |
||||
"userId":widget.userId, |
||||
// exitFull: () { |
||||
// setState(() {}); |
||||
// }, |
||||
}); |
||||
setState(() {}); |
||||
}, |
||||
child: communityItem(widget.comments[position], position), |
||||
); |
||||
}, |
||||
), |
||||
], |
||||
)); |
||||
} |
||||
|
||||
///动态内容 |
||||
Widget buildMedia(SubjectInfo subjectInfo, position) { |
||||
if (subjectInfo == null) { |
||||
return Container(); |
||||
} |
||||
Widget itemWidget = Container(); |
||||
if (subjectInfo.type == "image" && subjectInfo.images.length > 0) { |
||||
if (subjectInfo.images.length == 1) { |
||||
itemWidget = Container( |
||||
child: InkWell( |
||||
onTap: () { |
||||
Navigator.push( |
||||
context, |
||||
MaterialPageRoute( |
||||
builder: (context) => PhotoViewGalleryScreen( |
||||
images: subjectInfo.images, //传入图片list |
||||
index: 0, //传入当前点击的图片的index |
||||
))); |
||||
}, |
||||
child: MImage( |
||||
subjectInfo.images[0], |
||||
fit: BoxFit.contain, |
||||
radius: BorderRadius.circular(2), |
||||
width: MediaQuery.of(context).size.width / 1.5, |
||||
height: MediaQuery.of(context).size.width/1.5, |
||||
errorSrc: "assets/image/default_2_1.png", |
||||
fadeSrc: "assets/image/default_2_1.png", |
||||
)), |
||||
); |
||||
} else { |
||||
itemWidget = 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: InkWell( |
||||
onTap: () { |
||||
Navigator.push( |
||||
context, |
||||
MaterialPageRoute( |
||||
builder: (context) => PhotoViewGalleryScreen( |
||||
images: subjectInfo.images, //传入图片list |
||||
index: position, //传入当前点击的图片的index |
||||
))); |
||||
}, |
||||
child: MImage( |
||||
subjectInfo.images[position], |
||||
fit: BoxFit.cover, |
||||
aspectRatio: 1, |
||||
radius: BorderRadius.circular(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.isNotEmpty) { |
||||
itemWidget = Container( |
||||
width: MediaQuery.of(context).size.width, |
||||
height: MediaQuery.of(context).size.width / 7 * 5, |
||||
color: Colors.black, |
||||
child: Stack( |
||||
children: [ |
||||
Container( |
||||
width: double.infinity, |
||||
height: double.infinity, |
||||
child: MImage( |
||||
subjectInfo.video.replaceAll(".mp4", "_poster.jpg"), |
||||
fit: BoxFit.cover, |
||||
radius: BorderRadius.circular(2), |
||||
errorSrc: "assets/image/default_2_1.png", |
||||
fadeSrc: "assets/image/default_2_1.png", |
||||
), |
||||
), |
||||
Center( |
||||
child: Icon( |
||||
Icons.play_circle_outline, |
||||
color: Colors.white, |
||||
size: 60, |
||||
), |
||||
), |
||||
], |
||||
), |
||||
); |
||||
} |
||||
return Column( |
||||
mainAxisAlignment: MainAxisAlignment.center, |
||||
crossAxisAlignment: CrossAxisAlignment.start, |
||||
mainAxisSize: MainAxisSize.min, |
||||
children: [ |
||||
SizedBox( |
||||
height: 16.h, |
||||
), |
||||
itemWidget, |
||||
], |
||||
); |
||||
} |
||||
|
||||
Widget communityItem(ComunityComment comments, position) { |
||||
return Container( |
||||
width: double.infinity, |
||||
padding: EdgeInsets.all(16), |
||||
margin: EdgeInsets.only(bottom: 12), |
||||
color: Colors.white, |
||||
child: Column( |
||||
children: [ |
||||
Container( |
||||
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: [ |
||||
GestureDetector( |
||||
onTap: () { |
||||
Navigator.push( |
||||
context, |
||||
MaterialPageRoute( |
||||
builder: (context) => |
||||
PhotoViewGalleryScreen( |
||||
images: [ |
||||
(comments?.memberInfo?.avatar ?? "") |
||||
.isEmpty |
||||
? "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg" |
||||
: comments?.memberInfo?.avatar |
||||
], //传入图片list |
||||
index: 0, //传入当前点击的图片的index |
||||
), |
||||
)); |
||||
}, |
||||
child: MImage( |
||||
(comments?.memberInfo?.avatar ?? |
||||
"https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg"), |
||||
width: 44, |
||||
height: 44, |
||||
isCircle: true, |
||||
fit: BoxFit.cover, |
||||
errorSrc: "assets/image/default_1.png", |
||||
fadeSrc: "assets/image/default_1.png", |
||||
), |
||||
), |
||||
SizedBox( |
||||
width: 8, |
||||
), |
||||
Column( |
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
||||
crossAxisAlignment: CrossAxisAlignment.start, |
||||
children: [ |
||||
Text( |
||||
comments?.memberInfo?.nickname ?? "", |
||||
style: TextStyle( |
||||
fontSize: 15.sp, |
||||
fontWeight: MyFontWeight.semi_bold, |
||||
color: Color(0xFF1A1A1A), |
||||
), |
||||
), |
||||
Text( |
||||
comments?.createTime ?? "", |
||||
style: TextStyle( |
||||
fontSize: 13.sp, |
||||
fontWeight: MyFontWeight.regular, |
||||
color: Color(0xFF808080), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
], |
||||
), |
||||
), |
||||
if ((comments?.memberInfo?.mid ?? "") != (widget.userId)) |
||||
GestureDetector( |
||||
onTap: () { |
||||
setState(() { |
||||
if (widget.commentType == 0) { |
||||
comments.selfFollow = !(comments.selfFollow ?? false); |
||||
_vipFollow(comments?.memberInfo?.mid,comments?.selfFollow ?? false); |
||||
} else { |
||||
showDeleteDialog(position); |
||||
} |
||||
}); |
||||
}, |
||||
child: |
||||
(widget.commentType == 0) ? |
||||
Container( |
||||
width: 56.w, |
||||
height: 25.h, |
||||
alignment: Alignment.center, |
||||
child: RoundButton( |
||||
height: 25.h, |
||||
backgroup: (comments?.selfFollow ?? false) |
||||
? Color(0xFFE6E6E6) |
||||
: Color(0xFF32A060), |
||||
textColor: (comments?.selfFollow ?? false) |
||||
? Color(0xFF808080) |
||||
: Colors.white, |
||||
text: (comments?.selfFollow ?? false) |
||||
? "已关注" |
||||
: "关注", |
||||
radius: 20, |
||||
icons: Icon( |
||||
(comments?.selfFollow ?? false) |
||||
? Icons.check |
||||
: Icons.add, |
||||
color: (comments?.selfFollow ?? false) |
||||
? Color(0xFF808080) |
||||
: Colors.white, |
||||
size: 15, |
||||
), |
||||
)) |
||||
: Padding( |
||||
padding: EdgeInsets.all(20), |
||||
child: Icon( |
||||
Icons.close, |
||||
color: Colors.black, |
||||
size: 16, |
||||
), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
SizedBox( |
||||
height: 12.h, |
||||
), |
||||
Text( |
||||
comments.subject ?? "", |
||||
maxLines: 5, |
||||
overflow: TextOverflow.ellipsis, |
||||
style: TextStyle( |
||||
color: Color(0xFF1A1A1A), |
||||
fontWeight: MyFontWeight.regular, |
||||
fontSize: 15.sp, |
||||
), |
||||
), |
||||
buildMedia(comments?.subjectInfo, position), |
||||
// if (!widget.isDetails) |
||||
SizedBox( |
||||
height: 12.h, |
||||
), |
||||
// if (!comments.isDetails) |
||||
Row( |
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
||||
crossAxisAlignment: CrossAxisAlignment.center, |
||||
children: [ |
||||
IconText( |
||||
"${comments?.viewers ?? ""}", |
||||
space: 4.w, |
||||
leftImage: "assets/svg/liulanliang.svg", |
||||
iconSize: 16, |
||||
textStyle: TextStyle( |
||||
fontSize: 14.sp, |
||||
), |
||||
), |
||||
IconText( |
||||
"${comments.comments ?? 0}", |
||||
space: 4.w, |
||||
leftImage: "assets/svg/pinglun.svg", |
||||
iconSize: 16, |
||||
textStyle: TextStyle( |
||||
fontSize: 14.sp, |
||||
), |
||||
), |
||||
GestureDetector( |
||||
onTap: () {}, |
||||
child: IconText( |
||||
"${comments.likes ?? 0}", |
||||
space: 4.w, |
||||
leftImage: "assets/svg/xihuan.svg", |
||||
iconSize: 16, |
||||
textStyle: TextStyle( |
||||
fontSize: 14.sp, |
||||
), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
], |
||||
), |
||||
), |
||||
], |
||||
), |
||||
); |
||||
} |
||||
|
||||
///删除动态弹窗 |
||||
showDeleteDialog(index) { |
||||
showDialog( |
||||
context: context, |
||||
builder: (context) { |
||||
return AlertDialog( |
||||
content: Container( |
||||
width: MediaQuery.of(context).size.width - 84, |
||||
height: 130.h, |
||||
child: Column( |
||||
mainAxisAlignment: MainAxisAlignment.center, |
||||
crossAxisAlignment: CrossAxisAlignment.center, |
||||
children: [ |
||||
Text( |
||||
"确定要删除这条动态?", |
||||
style: TextStyle( |
||||
fontSize: 17.sp, |
||||
fontWeight: FontWeight.bold, |
||||
color: Colors.black, |
||||
), |
||||
), |
||||
SizedBox( |
||||
height: 30.h, |
||||
), |
||||
Row( |
||||
children: [ |
||||
Expanded( |
||||
child: InkWell( |
||||
child: BorderText( |
||||
text: "取消", |
||||
textColor: Color(0xFF32A060), |
||||
fontSize: 16.sp, |
||||
fontWeight: FontWeight.bold, |
||||
borderColor: Color(0xFF32A060), |
||||
radius: 4, |
||||
padding: EdgeInsets.all(12), |
||||
borderWidth: 1, |
||||
), |
||||
onTap: () { |
||||
Navigator.of(context).pop(); |
||||
}, |
||||
), |
||||
flex: 1, |
||||
), |
||||
SizedBox( |
||||
width: 16.w, |
||||
), |
||||
Expanded( |
||||
child: InkWell( |
||||
child: RoundButton( |
||||
text: "确定", |
||||
textColor: Colors.white, |
||||
radius: 4, |
||||
padding: EdgeInsets.all(12), |
||||
backgroup: Color(0xFF32A060), |
||||
fontSize: 16.sp, |
||||
fontWeight: FontWeight.bold, |
||||
), |
||||
onTap: () { |
||||
_deleteDynamic(widget.comments[index].id); |
||||
Navigator.of(context).pop(); |
||||
}, |
||||
), |
||||
flex: 1, |
||||
), |
||||
], |
||||
) |
||||
], |
||||
), |
||||
), |
||||
); |
||||
}, |
||||
); |
||||
} |
||||
} |
@ -0,0 +1,551 @@
|
||||
import 'dart:convert'; |
||||
|
||||
import 'package:dio/dio.dart'; |
||||
import 'package:flutter/cupertino.dart'; |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:flutter/services.dart'; |
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
||||
import 'package:huixiang/community/photo_view_gallery_screen.dart'; |
||||
import 'package:huixiang/generated/l10n.dart'; |
||||
import 'package:huixiang/retrofit/data/article.dart'; |
||||
import 'package:huixiang/retrofit/data/base_data.dart'; |
||||
import 'package:huixiang/retrofit/data/member_comment_list.dart'; |
||||
import 'package:huixiang/retrofit/data/page.dart'; |
||||
import 'package:huixiang/retrofit/retrofit_api.dart'; |
||||
import 'package:huixiang/utils/font_weight.dart'; |
||||
import 'package:huixiang/view_widget/custom_image.dart'; |
||||
import 'package:huixiang/view_widget/my_appbar.dart'; |
||||
import 'package:huixiang/view_widget/round_button.dart'; |
||||
import 'package:huixiang/view_widget/tips_dialog.dart'; |
||||
import 'package:huixiang/web/web_view/comment_list.dart'; |
||||
import 'package:huixiang/web/web_view/input_comment.dart'; |
||||
import 'package:shared_preferences/shared_preferences.dart'; |
||||
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
||||
import 'dart:ui'; |
||||
|
||||
import 'community_view/class_details_video.dart'; |
||||
|
||||
class NewCommunityDetails extends StatefulWidget { |
||||
final Map<String, dynamic> arguments; |
||||
|
||||
NewCommunityDetails({this.arguments}); |
||||
|
||||
@override |
||||
State<StatefulWidget> createState() { |
||||
return _NewCommunityDetails(); |
||||
} |
||||
} |
||||
|
||||
class _NewCommunityDetails extends State<NewCommunityDetails> with WidgetsBindingObserver { |
||||
ApiService apiService; |
||||
final GlobalKey commentKey = GlobalKey(); |
||||
final GlobalKey videoKey = GlobalKey(); |
||||
double height = 0; |
||||
final ScrollController scrollController = ScrollController(); |
||||
bool isKeyBoardShow = false; |
||||
double commentHeight = 60.h; |
||||
var commentFocus = FocusNode(); |
||||
String parenId = "0"; |
||||
String hintText = S.current.liuxianinjingcaidepinglunba; |
||||
final GlobalKey inputKey = GlobalKey(); |
||||
final TextEditingController commentTextController = TextEditingController(); |
||||
int commentTotal = 0; |
||||
List<MemberCommentList> memberList = []; |
||||
bool isShowImg = true; |
||||
Article article; |
||||
String commentsId; |
||||
String userId; |
||||
|
||||
@override |
||||
void initState() { |
||||
super.initState(); |
||||
commentsId = widget.arguments["commentsId"]; |
||||
userId = widget.arguments["userId"]; |
||||
WidgetsBinding.instance.addObserver(this); |
||||
queryDetails(commentsId); |
||||
} |
||||
|
||||
///详情接口 |
||||
queryDetails(id) async { |
||||
SharedPreferences value = await SharedPreferences.getInstance(); |
||||
if (apiService == null) |
||||
apiService = ApiService( |
||||
Dio(), |
||||
context: context, |
||||
token: value.getString("token"), |
||||
); |
||||
BaseData<Article> baseData = await apiService.informationInfo(id) |
||||
.catchError((onError) { |
||||
debugPrint(onError.toString()); |
||||
}); |
||||
if (baseData != null && baseData.isSuccess) { |
||||
setState(() { |
||||
article = baseData.data; |
||||
}); |
||||
} |
||||
} |
||||
|
||||
///关注/取关会员 |
||||
_vipFollow(followId, isFollow) async { |
||||
BaseData baseData = await apiService.follow(followId); |
||||
if (baseData != null && baseData.isSuccess) { |
||||
SmartDialog.showToast(isFollow ? "关注成功" : "取关成功", |
||||
alignment: Alignment.center); |
||||
setState(() {}); |
||||
} else { |
||||
// SmartDialog.showToast(baseData.msg, alignment: Alignment.center); |
||||
} |
||||
} |
||||
|
||||
@override |
||||
void didChangeMetrics() { |
||||
WidgetsBinding.instance.addPostFrameCallback((_) { |
||||
if (!mounted) return; |
||||
if (MediaQuery.of(context).viewInsets.bottom == 0) { |
||||
if (isKeyBoardShow) { |
||||
FocusScope.of(context).requestFocus(FocusNode()); |
||||
if (mounted) |
||||
setState(() { |
||||
hintText = S.current.liuxianinjingcaidepinglunba; |
||||
isKeyBoardShow = false; |
||||
}); |
||||
} |
||||
} else { |
||||
if (mounted) |
||||
setState(() { |
||||
isKeyBoardShow = true; |
||||
}); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
return AnnotatedRegion<SystemUiOverlayStyle>( |
||||
value: SystemUiOverlayStyle.light, |
||||
child: Material(child: Scaffold( |
||||
appBar: MyAppBar( |
||||
title: "动态详情", |
||||
titleColor: Colors.black, |
||||
titleSize: 18.sp, |
||||
background: Colors.white, |
||||
leading: true, |
||||
leadingColor: Colors.black, |
||||
), |
||||
body: Container( |
||||
margin: EdgeInsets.only(top:2.h), |
||||
child: Column( |
||||
children: [ |
||||
Expanded( |
||||
child: SingleChildScrollView( |
||||
physics: BouncingScrollPhysics(), |
||||
child: Column( |
||||
children: [ |
||||
Container( |
||||
padding: EdgeInsets.all(16), |
||||
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: [ |
||||
GestureDetector( |
||||
onTap: () { |
||||
Navigator.push( |
||||
context, |
||||
MaterialPageRoute( |
||||
builder: (context) => PhotoViewGalleryScreen( |
||||
images: [ |
||||
(article?.authorHeadImg ?? "") |
||||
.isEmpty |
||||
? "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg" |
||||
: article?.authorHeadImg |
||||
], //传入图片list |
||||
index: 0, //传入当前点击的图片的index |
||||
), |
||||
)); |
||||
}, |
||||
child: MImage( |
||||
(article?.authorHeadImg ?? |
||||
""), |
||||
width: 44, |
||||
height: 44, |
||||
isCircle: true, |
||||
fit: BoxFit.cover, |
||||
errorSrc: "assets/image/default_1.png", |
||||
fadeSrc: "assets/image/default_1.png", |
||||
), |
||||
), |
||||
SizedBox( |
||||
width: 8, |
||||
), |
||||
Column( |
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
||||
crossAxisAlignment: CrossAxisAlignment.start, |
||||
children: [ |
||||
Text( |
||||
article?.authorName ?? "", |
||||
style: TextStyle( |
||||
fontSize: 15.sp, |
||||
fontWeight: MyFontWeight.semi_bold, |
||||
color: Color(0xFF1A1A1A), |
||||
), |
||||
), |
||||
Text( |
||||
article?.createTime ?? "", |
||||
style: TextStyle( |
||||
fontSize: 13.sp, |
||||
fontWeight: MyFontWeight.regular, |
||||
color: Color(0xFF808080), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
], |
||||
), |
||||
), |
||||
if (article?.updateUser != userId) |
||||
GestureDetector( |
||||
onTap: () { |
||||
setState(() { |
||||
article.liked = |
||||
!(article.liked ?? false); |
||||
_vipFollow(article.updateUser, |
||||
article.liked ?? false); |
||||
}); |
||||
}, |
||||
child: |
||||
Container( |
||||
width: 56.w, |
||||
height: 25.h, |
||||
alignment: Alignment.center, |
||||
child: RoundButton( |
||||
height: 25.h, |
||||
backgroup: (article?.liked ?? false) |
||||
? Color(0xFFE6E6E6) |
||||
: Color(0xFF32A060), |
||||
textColor: (article?.liked ?? false) |
||||
? Color(0xFF808080) |
||||
: Colors.white, |
||||
text: (article?.liked ?? false) |
||||
? "已关注" |
||||
: "关注", |
||||
radius: 20, |
||||
icons: Icon( |
||||
(article?.liked ?? false) |
||||
? Icons.check |
||||
: Icons.add, |
||||
color: (article?.liked ?? false) |
||||
? Color(0xFF808080) |
||||
: Colors.white, |
||||
size: 15, |
||||
), |
||||
)) |
||||
), |
||||
], |
||||
), |
||||
SizedBox( |
||||
height: 12.h, |
||||
), |
||||
Text( |
||||
article?.mainTitle ?? "", |
||||
maxLines: 5, |
||||
overflow: TextOverflow.ellipsis, |
||||
style: TextStyle( |
||||
color: Color(0xFF1A1A1A), |
||||
fontWeight: MyFontWeight.regular, |
||||
fontSize: 15.sp, |
||||
), |
||||
), |
||||
buildMedia(article?.content), |
||||
], |
||||
), |
||||
), |
||||
CommentList( |
||||
commentKey, |
||||
article?.likes ?? 0, |
||||
commentsId, |
||||
4, |
||||
isKeyBoardShow, |
||||
_reply, |
||||
_delCommentTips, |
||||
12.sp, |
||||
requestApiFinish: (total){setState(() { |
||||
commentTotal = total; |
||||
});}, |
||||
), |
||||
if (memberList == null || memberList.length == 0) |
||||
Container( |
||||
width: double.infinity, |
||||
alignment: Alignment.topCenter, |
||||
margin: EdgeInsets.only(top: 40), |
||||
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, |
||||
isLike: article?.liked ?? false, |
||||
), |
||||
], |
||||
), |
||||
), |
||||
),) |
||||
); |
||||
} |
||||
|
||||
///动态内容 |
||||
Widget buildMedia(String subjectInfo) { |
||||
if (subjectInfo == null || !subjectInfo.startsWith("{")) { |
||||
return Container(); |
||||
} |
||||
var cnt = jsonDecode(subjectInfo); |
||||
Widget itemWidget = Container(); |
||||
if (cnt["type"] == "image" && |
||||
cnt["images"] != null && |
||||
cnt["images"].length > 0) { |
||||
if (cnt["images"].length == 1) { |
||||
itemWidget = Container( |
||||
child: InkWell( |
||||
onTap: () { |
||||
// ImagePickers.previewImages(subjectInfo.images,0); |
||||
Navigator.push( |
||||
context, |
||||
MaterialPageRoute( |
||||
builder: (context) => PhotoViewGalleryScreen( |
||||
images: cnt["images"], //传入图片list |
||||
index: 0, //传入当前点击的图片的index |
||||
), |
||||
), |
||||
); |
||||
}, |
||||
child: MImage( |
||||
cnt["images"][0], |
||||
radius: BorderRadius.circular(2), |
||||
fit: BoxFit.contain, |
||||
width: MediaQuery.of(context).size.width / 1.5, |
||||
height: MediaQuery.of(context).size.width, |
||||
errorSrc: "assets/image/default_2_1.png", |
||||
fadeSrc: "assets/image/default_2_1.png", |
||||
)), |
||||
); |
||||
} else { |
||||
itemWidget = GridView.builder( |
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( |
||||
crossAxisCount: |
||||
(cnt["images"].length == 2 || cnt["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: InkWell( |
||||
onTap: () { |
||||
// ImagePickers.previewImages(subjectInfo.images, position); |
||||
Navigator.push( |
||||
context, |
||||
MaterialPageRoute( |
||||
builder: (context) => PhotoViewGalleryScreen( |
||||
images: cnt["images"], //传入图片list |
||||
index: position, //传入当前点击的图片的index |
||||
), |
||||
), |
||||
); |
||||
}, |
||||
child: MImage( |
||||
cnt["images"][position], |
||||
fit: BoxFit.cover, |
||||
aspectRatio: 1, |
||||
radius: BorderRadius.circular(1), |
||||
errorSrc: "assets/image/default_2_1.png", |
||||
fadeSrc: "assets/image/default_2_1.png", |
||||
), |
||||
), |
||||
); |
||||
}, |
||||
itemCount: cnt["images"].length, |
||||
); |
||||
} |
||||
} else if (cnt["type"] == "video" && |
||||
cnt["video"] != null && |
||||
cnt["video"].isNotEmpty) { |
||||
itemWidget = Container( |
||||
child:ClassDetailsVideo(key:videoKey,exitFull: (){setState(() {});}, |
||||
coverImg: cnt["video"].toString().replaceAll(".mp4", "_poster.jpg"),isShowImg: this.isShowImg, |
||||
changeShowImg: (isShowImg){setState(() { |
||||
this.isShowImg = isShowImg; |
||||
});},videoUrl: cnt["video"], |
||||
heightFun: (height) { |
||||
this.height = |
||||
height + |
||||
MediaQuery |
||||
.of(context) |
||||
.padding |
||||
.top + |
||||
kToolbarHeight + |
||||
24; |
||||
if (mounted) setState(() {}); |
||||
},) |
||||
); |
||||
} |
||||
return Column( |
||||
mainAxisAlignment: MainAxisAlignment.center, |
||||
crossAxisAlignment: CrossAxisAlignment.start, |
||||
mainAxisSize: MainAxisSize.min, |
||||
children: [ |
||||
SizedBox( |
||||
height: 16.h, |
||||
), |
||||
itemWidget, |
||||
], |
||||
); |
||||
} |
||||
|
||||
///给文章/活动点赞 |
||||
_queryInformationLikes() async { |
||||
BaseData baseData = await apiService.informationLikes(commentsId).catchError((onError) {}); |
||||
if (baseData != null && baseData.isSuccess) { |
||||
commentKey.currentState.setState(() {}); |
||||
setState(() { |
||||
if (article?.liked ?? false) |
||||
article?.likes -= 1; |
||||
else |
||||
article?.likes += 1; |
||||
article?.liked = !(article.liked ?? false); |
||||
}); |
||||
} else { |
||||
SmartDialog.showToast(baseData.msg, alignment: Alignment.center); |
||||
} |
||||
} |
||||
|
||||
///动态发布评论 |
||||
_queryMemberComment(String content) async { |
||||
BaseData baseData = await apiService.memberComment({ |
||||
"content": content, |
||||
"parentId": parenId, |
||||
"relationalId": commentsId, |
||||
"relationalType":4 |
||||
}).catchError((error) {}); |
||||
if (baseData != null && baseData.isSuccess) { |
||||
CommentListState state = commentKey.currentState; |
||||
state.queryMemberCommentList(); |
||||
commentTextController.text = ""; |
||||
FocusScope.of(context).unfocus(); |
||||
_queryMemberCommentList(); |
||||
} |
||||
} |
||||
|
||||
///滑动到评论列表 |
||||
_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, |
||||
); |
||||
} |
||||
|
||||
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); |
||||
} |
||||
} |
||||
|
||||
///删除评论的提示 |
||||
_delCommentTips(memberComment) { |
||||
SmartDialog.show(widget: Tips(() { |
||||
delComment(memberComment); |
||||
})); |
||||
} |
||||
|
||||
///删除评论 |
||||
delComment(memberComment) async { |
||||
BaseData baseData = await apiService.delComment(memberComment.id); |
||||
if (baseData != null && baseData.isSuccess) { |
||||
CommentListState state = commentKey.currentState; |
||||
state.queryMemberCommentList(); |
||||
} |
||||
} |
||||
|
||||
///评论 回复 |
||||
_reply(memberComment) { |
||||
FocusScope.of(context).requestFocus(commentFocus); |
||||
parenId = memberComment.id; |
||||
hintText = S.of(context).huifu_("${memberComment.username}"); |
||||
} |
||||
|
||||
///评论列表 |
||||
_queryMemberCommentList() async { |
||||
SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); |
||||
if (apiService == null) |
||||
apiService = ApiService( |
||||
Dio(), |
||||
context: context, |
||||
token: sharedPreferences.getString("token"), |
||||
showLoading: false, |
||||
); |
||||
BaseData<PageInfo<MemberCommentList>> baseData = |
||||
await apiService.memberCommentList({ |
||||
"pageNum": 1, |
||||
"pageSize": 100, |
||||
"relationalId": commentsId, |
||||
"relationalType":4, |
||||
}).catchError((error) {}); |
||||
if (baseData != null && baseData.isSuccess) { |
||||
commentTotal = baseData.data.size; |
||||
memberList = baseData.data.list; |
||||
contentHeight(); |
||||
if (mounted) setState(() {}); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,35 @@
|
||||
import 'dart:io'; |
||||
|
||||
import 'package:path_provider/path_provider.dart'; |
||||
|
||||
class ImgCachePath{ |
||||
factory ImgCachePath() => _getInstance(); |
||||
|
||||
static ImgCachePath get instance => _getInstance(); |
||||
|
||||
static ImgCachePath _instance; |
||||
|
||||
String _path; |
||||
|
||||
String get path => _path; |
||||
|
||||
ImgCachePath._internal(){ |
||||
fileFromDocsDir(); |
||||
} |
||||
|
||||
fileFromDocsDir() async { |
||||
Directory tempDir = await getTemporaryDirectory(); |
||||
Directory directory = new Directory('${tempDir.path}/ImgCache'); |
||||
if (!directory.existsSync()) { |
||||
directory.createSync(); |
||||
} |
||||
_path = directory.path; |
||||
} |
||||
|
||||
static ImgCachePath _getInstance(){ |
||||
if(_instance == null){ |
||||
_instance = ImgCachePath._internal(); |
||||
} |
||||
return _instance; |
||||
} |
||||
} |
Loading…
Reference in new issue