我的动态

pull/1/head
张萌 3 years ago
parent 3da2ce23ec
commit c52ce50277

@ -103,6 +103,9 @@ class _Message {
}
class _Community {
///
String get singleComment => '/app/user/community/comment/findById';
///
String get topicDetail => '/app/user/community/topic/findById';

@ -1,7 +1,7 @@
import 'package:common_utils/common_utils.dart';
import 'package:aku_new_community/model/common/img_model.dart';
import 'package:common_utils/common_utils.dart';
@Deprecated('old model to deprecate')
class MyEventItemModel {
int? id;
String? content;

@ -32,7 +32,7 @@ CommentTwoList _$CommentTwoListFromJson(Map<String, dynamic> json) =>
createId: json['createId'] as int,
createName: json['createName'] as String,
parentId: json['parentId'] as int,
parentName: json['parentName'] as String,
parentName: json['parentName'] as String?,
createDate: json['createDate'] as String,
avatarImgList: (json['avatarImgList'] as List<dynamic>)
.map((e) => ImgModel.fromJson(e as Map<String, dynamic>))

@ -0,0 +1,36 @@
import 'package:aku_new_community/model/common/img_model.dart';
import 'package:aku_new_community/models/community/all_dynamic_list_model.dart';
import 'package:json_annotation/json_annotation.dart';
part 'dynamic_my_list_body.g.dart';
@JsonSerializable()
class DynamicMyListBody {
final int id;
final String? content;
final int isComment;
final int isPublic;
final String createDate;
final int likes;
final int views;
final int commentNum;
final List<ImgModel> dynamicImgList;
final List<TopicTag> topicTags;
final bool isLike;
factory DynamicMyListBody.fromJson(Map<String, dynamic> json) =>
_$DynamicMyListBodyFromJson(json);
const DynamicMyListBody({
required this.id,
this.content,
required this.isComment,
required this.isPublic,
required this.createDate,
required this.likes,
required this.views,
required this.commentNum,
required this.dynamicImgList,
required this.topicTags,
required this.isLike,
});
}

@ -0,0 +1,26 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'dynamic_my_list_body.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
DynamicMyListBody _$DynamicMyListBodyFromJson(Map<String, dynamic> json) =>
DynamicMyListBody(
id: json['id'] as int,
content: json['content'] as String?,
isComment: json['isComment'] as int,
isPublic: json['isPublic'] as int,
createDate: json['createDate'] as String,
likes: json['likes'] as int,
views: json['views'] as int,
commentNum: json['commentNum'] as int,
dynamicImgList: (json['dynamicImgList'] as List<dynamic>)
.map((e) => ImgModel.fromJson(e as Map<String, dynamic>))
.toList(),
topicTags: (json['topicTags'] as List<dynamic>)
.map((e) => TopicTag.fromJson(e as Map<String, dynamic>))
.toList(),
isLike: json['isLike'] as bool,
);

@ -0,0 +1,25 @@
import 'package:aku_new_community/model/common/img_model.dart';
import 'package:json_annotation/json_annotation.dart';
part 'dynamic_my_list_head.g.dart';
@JsonSerializable()
class DynamicMyListHead {
final int id;
final String createName;
final List<ImgModel> avatarImgList;
final int dynamicNum;
final int commentNum;
final int likesNum;
factory DynamicMyListHead.fromJson(Map<String, dynamic> json) =>
_$DynamicMyListHeadFromJson(json);
const DynamicMyListHead({
required this.id,
required this.createName,
required this.avatarImgList,
required this.dynamicNum,
required this.commentNum,
required this.likesNum,
});
}

@ -0,0 +1,19 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'dynamic_my_list_head.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
DynamicMyListHead _$DynamicMyListHeadFromJson(Map<String, dynamic> json) =>
DynamicMyListHead(
id: json['id'] as int,
createName: json['createName'] as String,
avatarImgList: (json['avatarImgList'] as List<dynamic>)
.map((e) => ImgModel.fromJson(e as Map<String, dynamic>))
.toList(),
dynamicNum: json['dynamicNum'] as int,
commentNum: json['commentNum'] as int,
likesNum: json['likesNum'] as int,
);

@ -3,9 +3,9 @@ import 'package:aku_new_community/constants/sars_api.dart';
import 'package:aku_new_community/model/community/activity_item_model.dart';
import 'package:aku_new_community/model/community/board_model.dart';
import 'package:aku_new_community/model/community/hot_news_model.dart';
import 'package:aku_new_community/model/community/my_event_item_model.dart';
import 'package:aku_new_community/model/community/swiper_model.dart';
import 'package:aku_new_community/model/good/market_swiper_model.dart';
import 'package:aku_new_community/models/community/dynamic_my_list_body.dart';
import 'package:aku_new_community/models/community/topic_model.dart';
import 'package:aku_new_community/models/market/goods_popular_model.dart';
import 'package:aku_new_community/models/market/market_all_category_model.dart';
@ -28,13 +28,13 @@ class CommunityFunc {
}
///
static Future<List<MyEventItemModel>> getMyEventItem() async {
static Future<List<DynamicMyListBody>> getMyEventItem() async {
BaseListModel model = await NetUtil().getList(
API.community.myEvent,
SARSAPI.community.dynamicMyListL,
params: {'pageNum': 1, 'size': 8},
);
if (model.rows.length == 0) return [];
return model.rows.map((e) => MyEventItemModel.fromJson(e)).toList();
return model.rows.map((e) => DynamicMyListBody.fromJson(e)).toList();
}
///

@ -1,7 +1,6 @@
import 'dart:math';
import 'package:aku_new_community/base/base_style.dart';
import 'package:aku_new_community/constants/api.dart';
import 'package:aku_new_community/constants/sars_api.dart';
import 'package:aku_new_community/model/common/img_model.dart';
import 'package:aku_new_community/models/community/comment_list_model.dart';
@ -14,6 +13,7 @@ import 'package:aku_new_community/utils/headers.dart';
import 'package:aku_new_community/utils/login_util.dart';
import 'package:aku_new_community/utils/network/base_model.dart';
import 'package:aku_new_community/utils/network/net_util.dart';
import 'package:aku_new_community/widget/bee_divider.dart';
import 'package:aku_new_community/widget/bee_scaffold.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:common_utils/common_utils.dart';
@ -47,33 +47,42 @@ class _EventDetailPageState extends State<EventDetailPage> {
}
TextEditingController _textEditingController = TextEditingController();
int rootId = 0;
int parentId = 0;
//id
int _rootId = 0;
//id
int _parentId = 0;
int _page = 1;
int _type = 1;
int _size = 10;
int _currentCommentIndex = 0;
List<CommentListModel> _comments = [];
List<bool> _folds = [];
List<bool> _likes = [];
//
FocusNode _focusNode = FocusNode();
Map<String, dynamic> get params => {
'rootId': rootId,
'parentId': parentId,
'rootId': _rootId,
'parentId': _parentId,
'dynamicId': widget.dynamicId,
'content': _textEditingController.text
};
Future updateComments() async {
var base = await NetUtil().getList(SARSAPI.community.commentList, params: {
'pageNum': _page,
'size': _size,
'dynamicId': widget.dynamicId,
'type': _type,
var base = await NetUtil().get(SARSAPI.community.singleComment, params: {
'commentId': _comments[_currentCommentIndex].id,
});
_comments.replaceRange((_page - 1) * _size, _page * _size,
base.rows.map((e) => CommentListModel.fromJson(e)).toList());
if (base.success) {
_comments.removeAt(_currentCommentIndex);
_comments.insert(
_currentCommentIndex, CommentListModel.fromJson(base.data));
} else {
BotToast.showText(text: base.msg);
}
setState(() {});
}
@ -120,11 +129,6 @@ class _EventDetailPageState extends State<EventDetailPage> {
));
if (result == true) {
await NetUtil().get(
API.community.deleteMyEvent,
params: {'dynamicId': widget.dynamicId},
showMessage: true,
);
if (widget.onDelete != null) {
widget.onDelete!();
Get.back();
@ -145,7 +149,6 @@ class _EventDetailPageState extends State<EventDetailPage> {
);
_model = DynamicDetailModel.fromJson(model.data);
_page = 1;
var base =
await NetUtil().getList(SARSAPI.community.commentList, params: {
'pageNum': _page,
@ -155,6 +158,14 @@ class _EventDetailPageState extends State<EventDetailPage> {
});
_comments =
base.rows.map((e) => CommentListModel.fromJson(e)).toList();
_folds = List.filled(_size, true);
_comments.forEach((element) {
if (element.isLike) {
_likes.add(true);
} else {
_likes.add(false);
}
});
setState(() {});
},
onLoad: () async {
@ -167,8 +178,17 @@ class _EventDetailPageState extends State<EventDetailPage> {
'type': _type,
});
if (_comments.length < base.total) {
_comments.addAll(
base.rows.map((e) => CommentListModel.fromJson(e)).toList());
var _list =
base.rows.map((e) => CommentListModel.fromJson(e)).toList();
_comments.addAll(_list);
_folds.addAll(List.filled(_list.length, true));
_list.forEach((element) {
if (element.isLike) {
_likes.add(true);
} else {
_likes.add(false);
}
});
}
setState(() {});
},
@ -178,18 +198,30 @@ class _EventDetailPageState extends State<EventDetailPage> {
SliverToBoxAdapter(
child: Column(
children: [
ChatCardDetail(
GestureDetector(
onTap: () {
_rootId = 0;
_parentId = 0;
},
child: ChatCardDetail(
model: _model!,
hideLine: true,
canTap: false,
),
),
_renderLikeAndCommentWidget(),
],
),
),
SliverList(
delegate: SliverChildListDelegate(
_comments.map((e) => _commentWidget(e)).toList()))
delegate: SliverChildListDelegate(_comments
.mapIndexed((e, index) => _commentWidget(e, index))
.toList()
.sepWidget(
separate: BeeDivider.horizontal(
indent: 32.w,
endIndent: 32.w,
))))
],
),
);
@ -257,8 +289,9 @@ class _EventDetailPageState extends State<EventDetailPage> {
);
}
Widget _commentWidget(CommentListModel model) {
Widget _commentWidget(CommentListModel model, int rootIndex) {
return Container(
// key: UniqueKey(),
color: Colors.white,
padding: EdgeInsets.symmetric(vertical: 32.w, horizontal: 32.w),
width: double.infinity,
@ -313,7 +346,18 @@ class _EventDetailPageState extends State<EventDetailPage> {
40.hb,
model.content.text.size(28.sp).color(ktextSubColor).make(),
30.hb,
Row(
GestureDetector(
onTap: () async {
var res =
await NetUtil().get(SARSAPI.community.commentLike, params: {
'commentId': model.id,
});
if (res.success) {
_likes[rootIndex] = !_likes[rootIndex];
setState(() {});
}
},
child: Row(
children: [
Spacer(),
Image.asset(
@ -322,13 +366,29 @@ class _EventDetailPageState extends State<EventDetailPage> {
height: 40.w,
),
5.wb,
'${model.likes}'.text.size(24.sp).color(Color(0xFF999999)).make(),
'${model.likes}'
.text
.size(24.sp)
.color(Color(0xFF999999))
.make(),
32.wb,
GestureDetector(
onTap: () {
_rootId = model.id;
_parentId = model.id;
_focusNode.requestFocus();
_currentCommentIndex = rootIndex;
},
child: Row(
children: [
Image.asset(
R.ASSETS_ICONS_COMMUNITY_COMMENT_PNG,
width: 40.w,
height: 40.w,
),
],
),
),
5.wb,
'${model.commentNum}'
.text
@ -337,10 +397,12 @@ class _EventDetailPageState extends State<EventDetailPage> {
.make(),
],
),
),
40.hb,
model.commentTwoList.isEmpty
? SizedBox.shrink()
: Container(
alignment: Alignment.topLeft,
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.06),
borderRadius: BorderRadius.circular(16.w)),
@ -349,11 +411,20 @@ class _EventDetailPageState extends State<EventDetailPage> {
padding:
EdgeInsets.symmetric(vertical: 24.w, horizontal: 32.w),
child: Column(
children: model.commentTwoList
.map((e) =>
_subCommentWidget(e, model.createId, model.id))
.toList()
.sepWidget(separate: 24.hb),
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
...List.generate(
model.commentTwoList.length < 3
? model.commentTwoList.length
: 3,
(index) => _subCommentWidget(
model.commentTwoList[index],
model.createId,
model.id,
rootIndex)),
if (model.commentTwoList.length > 3)
_foldComment(model, rootIndex)
].sepWidget(separate: 24.hb),
),
),
],
@ -361,12 +432,43 @@ class _EventDetailPageState extends State<EventDetailPage> {
);
}
Widget _subCommentWidget(CommentTwoList model, int createId, int rootId) {
Widget _foldComment(CommentListModel model, int rootIndex) {
return _folds[rootIndex]
? Row(
children: [
'共有${model.commentNum}条回复'
.text
.size(28.sp)
.color(Colors.black.withOpacity(0.45))
.make(),
Spacer(),
TextButton(
onPressed: () {
_folds[rootIndex] = false;
setState(() {});
},
child: '展开'.text.size(28.sp).color(Color(0xFF5D98F9)).make())
],
)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
...List.generate(
model.commentTwoList.length - 3,
(index) => _subCommentWidget(model.commentTwoList[index + 3],
model.createId, model.id, rootIndex))
].sepWidget(separate: 24.hb),
);
}
Widget _subCommentWidget(
CommentTwoList model, int createId, int rootId, int rootIndex) {
return GestureDetector(
onTap: () {
rootId = rootId;
parentId = model.id;
_rootId = rootId;
_parentId = model.id;
_focusNode.requestFocus();
_currentCommentIndex = rootIndex;
},
child: RichText(
text: TextSpan(
@ -376,11 +478,13 @@ class _EventDetailPageState extends State<EventDetailPage> {
fontSize: 28.sp,
),
children: [
if (rootId == model.createId)
if (createId == model.createId)
WidgetSpan(
child: Container(
width: 56.w,
height: 28.w,
margin: EdgeInsets.only(left: 4.w, right: 4.w, bottom: 4.w),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color(0xFFF8B133),
borderRadius: BorderRadius.circular(4.w)),
@ -423,6 +527,8 @@ class _EventDetailPageState extends State<EventDetailPage> {
width: double.infinity,
height: 100.w,
padding: EdgeInsets.symmetric(vertical: 16.w, horizontal: 32.w),
margin:
EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
decoration: BoxDecoration(
color: Colors.white,
),
@ -438,6 +544,7 @@ class _EventDetailPageState extends State<EventDetailPage> {
child: TextField(
controller: _textEditingController,
focusNode: _focusNode,
autofocus: false,
decoration: InputDecoration(
hintText: '参与评论',
contentPadding:
@ -465,7 +572,12 @@ class _EventDetailPageState extends State<EventDetailPage> {
.post(SARSAPI.community.commentInsert, params: params);
if (res.success) {
_textEditingController.clear();
if (_rootId == 0) {
_refreshController.callRefresh();
} else {
await updateComments();
_focusNode.unfocus();
}
setState(() {});
} else {
BotToast.showText(text: res.msg);

@ -1,20 +1,22 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:aku_new_community/constants/api.dart';
import 'package:aku_new_community/constants/sars_api.dart';
import 'package:aku_new_community/model/common/img_model.dart';
import 'package:aku_new_community/model/community/my_event_item_model.dart';
import 'package:aku_new_community/models/community/dynamic_my_list_body.dart';
import 'package:aku_new_community/models/community/dynamic_my_list_head.dart';
import 'package:aku_new_community/pages/things_page/widget/bee_list_view.dart';
import 'package:aku_new_community/ui/community/community_views/widgets/my_event_card.dart';
import 'package:aku_new_community/utils/headers.dart';
import 'package:aku_new_community/utils/login_util.dart';
import 'package:aku_new_community/utils/network/net_util.dart';
import 'package:aku_new_community/widget/line/vertical_line_painter.dart';
import 'package:aku_new_community/widget/picker/bee_image_preview.dart';
import 'package:aku_new_community/widget/views/bee_grid_image_view.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import '../community_func.dart';
class MyCommunityView extends StatefulWidget {
@ -28,7 +30,8 @@ class MyCommunityViewState extends State<MyCommunityView>
with AutomaticKeepAliveClientMixin {
EasyRefreshController _refreshController = EasyRefreshController();
bool _onload = true;
List<MyEventItemModel> _myEventItems = [];
List<DynamicMyListBody> _myEventItems = [];
DynamicMyListHead? _head;
refresh() {
_refreshController.callRefresh();
@ -37,21 +40,7 @@ class MyCommunityViewState extends State<MyCommunityView>
@override
Widget build(BuildContext context) {
super.build(context);
return EasyRefresh(
firstRefresh: true,
header: MaterialHeader(),
controller: _refreshController,
onRefresh: () async {
// API.community.myEvent
_myEventItems = await CommunityFunc.getMyEventItem();
_onload = false;
setState(() {});
},
child: _onload
? SizedBox()
: ListView(
children: [
Container(
var head = Container(
width: double.infinity,
decoration: BoxDecoration(
image: new DecorationImage(
@ -70,23 +59,19 @@ class MyCommunityViewState extends State<MyCommunityView>
height: 132.w,
),
32.hb,
'吼姆拉'
'${_head?.createName}'
.text
.size(32.sp)
.fontWeight(FontWeight.bold)
.color(Color(0xD9000000))
.make(),
12.hb,
'当一个新时代的天之圣杯'
.text
.size(24.sp)
.color(Color(0x73000000))
.make(),
'当一个新时代的有志青年'.text.size(24.sp).color(Color(0x73000000)).make(),
32.hb,
],
),
),
Container(
);
var headNum = Container(
width: double.infinity,
height: 156.w,
color: Colors.white,
@ -99,17 +84,13 @@ class MyCommunityViewState extends State<MyCommunityView>
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
'111'
'${_head?.dynamicNum}'
.text
.size(40.sp)
.fontWeight(FontWeight.bold)
.color(Color(0xD9000000))
.make(),
'动态'
.text
.size(24.sp)
.color(Color(0x73000000))
.make(),
'动态'.text.size(24.sp).color(Color(0x73000000)).make(),
],
),
),
@ -118,17 +99,13 @@ class MyCommunityViewState extends State<MyCommunityView>
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
'111'
'${_head?.commentNum}'
.text
.size(40.sp)
.fontWeight(FontWeight.bold)
.color(Color(0xD9000000))
.make(),
'动态'
.text
.size(24.sp)
.color(Color(0x73000000))
.make(),
'评论'.text.size(24.sp).color(Color(0x73000000)).make(),
],
),
),
@ -137,26 +114,45 @@ class MyCommunityViewState extends State<MyCommunityView>
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
'111'
'${_head?.likesNum}'
.text
.size(40.sp)
.fontWeight(FontWeight.bold)
.color(Color(0xD9000000))
.make(),
'动态'
.text
.size(24.sp)
.color(Color(0x73000000))
.make(),
'点赞'.text.size(24.sp).color(Color(0x73000000)).make(),
],
),
),
],
),
),
..._myEventItems.map(
);
return EasyRefresh(
firstRefresh: true,
header: MaterialHeader(),
controller: _refreshController,
onRefresh: () async {
_myEventItems = await CommunityFunc.getMyEventItem();
var base = await NetUtil().get(SARSAPI.community.dynamicMyListH);
if (base.success) {
_head = DynamicMyListHead.fromJson(base.data);
}
_onload = false;
setState(() {});
},
child: _onload
? SizedBox()
: ListView(
children: [
head,
headNum,
20.hb,
..._myEventItems
.map(
(e) => _getMoments(e),
),
)
.toList()
.sepWidget(separate: 20.hb),
//_getMoments(),
// _getMoments(),
@ -186,17 +182,21 @@ class MyCommunityViewState extends State<MyCommunityView>
);
}
Widget _getMoments(MyEventItemModel item) {
Widget _getMoments(DynamicMyListBody item) {
return Container(
padding:
EdgeInsets.only(top: 32.w, left: 25.w, right: 32.w, bottom: 32.w),
color: Colors.white,
child: CustomPaint(
painter: VerticalLinePainter(
color: Color(0x0F000000), //
width: 4.w, //UI
paddingTop: 100.w, //UI
paddingLeft: 0, //UI
color: Color(0x0F000000),
//
width: 4.w,
//UI
paddingTop: 100.w,
//UI
paddingLeft: 0,
//UI
paddingBottom: 100.w), //UI
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
@ -310,9 +310,9 @@ class MyCommunityViewState extends State<MyCommunityView>
);
}
_renderImage(MyEventItemModel item) {
if (item.imgUrl!.isEmpty) return SizedBox();
if (item.imgUrl!.length == 1)
_renderImage(DynamicMyListBody item) {
if (item.dynamicImgList.isEmpty) return SizedBox();
if (item.dynamicImgList.length == 1)
return MaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
padding: EdgeInsets.zero,
@ -323,8 +323,8 @@ class MyCommunityViewState extends State<MyCommunityView>
),
onPressed: () {
BeeImagePreview.toPath(
path: ImgModel.first(item.imgUrl),
tag: ImgModel.first(item.imgUrl),
path: ImgModel.first(item.dynamicImgList),
tag: ImgModel.first(item.dynamicImgList),
);
},
child: ConstrainedBox(
@ -333,10 +333,10 @@ class MyCommunityViewState extends State<MyCommunityView>
maxWidth: 300.w,
),
child: Hero(
tag: ImgModel.first(item.imgUrl),
tag: ImgModel.first(item.dynamicImgList),
child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: SARSAPI.image(ImgModel.first(item.imgUrl)),
image: SARSAPI.image(ImgModel.first(item.dynamicImgList)),
imageErrorBuilder: (context, error, stackTrace) {
return Image.asset(
R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
@ -351,7 +351,8 @@ class MyCommunityViewState extends State<MyCommunityView>
else
return Container(
width: 552.w,
child: BeeGridImageView(urls: item.imgUrl!.map((e) => e.url).toList()),
child: BeeGridImageView(
urls: item.dynamicImgList.map((e) => e.url).toList()),
);
}

Loading…
Cancel
Save