初始化
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hgdj/hj_page/comment/cell/comment_item.dart';
|
||||
import 'package:hgdj/hj_page/comment/comment_mixin.dart';
|
||||
import 'package:hgdj/hj_page/comment/widget/comment_foot_view.dart';
|
||||
import 'package:hgdj/tools_base/loading/loading_center_widget.dart';
|
||||
import 'package:hgdj/tools_base/refresh/pull_refresh.dart';
|
||||
|
||||
import '../home/widget/quick_search_view.dart';
|
||||
|
||||
class CommentLogic extends GetxController with CommentMixin {
|
||||
final String objId;
|
||||
|
||||
final String commentType;
|
||||
|
||||
@override
|
||||
final Function(int)? totalCallback;
|
||||
|
||||
CommentLogic(
|
||||
this.objId, {
|
||||
this.commentType = 'video',
|
||||
this.totalCallback,
|
||||
}) : super();
|
||||
|
||||
bool isLoading = true;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
id = objId;
|
||||
objType = commentType;
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
isLoading = false;
|
||||
fetchComments(objId);
|
||||
}
|
||||
}
|
||||
|
||||
class CommentView extends StatelessWidget {
|
||||
final bool showInput;
|
||||
final String objId;
|
||||
final String objType; // video, cartoon
|
||||
final Function(int)? totalCallback;
|
||||
|
||||
const CommentView(
|
||||
this.objId, {
|
||||
super.key,
|
||||
this.showInput = true,
|
||||
this.objType = 'video',
|
||||
this.totalCallback,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetBuilder(
|
||||
init: CommentLogic(objId,
|
||||
commentType: objType, totalCallback: totalCallback),
|
||||
tag: objId,
|
||||
builder: (logic) => LayoutBuilder(builder: (_, cons) {
|
||||
if (cons.maxHeight < 58) return SizedBox.shrink();
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: pullYsRefresh(
|
||||
onInit: (refreshCtr) => logic.refreshCtr = refreshCtr,
|
||||
onLoading: (_) => logic.fetchComments(objId),
|
||||
onRefresh: (_) => logic.fetchComments(objId, isRefresh: true),
|
||||
child: () {
|
||||
if (logic.isLoading) return LoadingCenterWidget();
|
||||
if (logic.comments.isEmpty) return CErrorWidget();
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
if (logic.quickSearchList.isNotEmpty)
|
||||
SliverToBoxAdapter(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(bottom: 12),
|
||||
margin: EdgeInsets.fromLTRB(12, 0, 12, 12),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom:
|
||||
BorderSide(color: Color(0x08ffffff)))),
|
||||
child: QuickSearchView(logic.quickSearchList),
|
||||
),
|
||||
),
|
||||
SliverList.builder(
|
||||
itemCount: logic.comments.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final topIndex = logic.topPinnedCommentIndex;
|
||||
final showBanner = index == topIndex &&
|
||||
logic.commentTopBanners.isNotEmpty;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: CommentItem(
|
||||
key: ValueKey(logic.comments[index].id),
|
||||
logic.comments[index],
|
||||
objId: objId,
|
||||
topBanners:
|
||||
showBanner ? logic.commentTopBanners : null,
|
||||
replyHandler: (comment, {reply}) =>
|
||||
logic.readyReplyComment(comment,
|
||||
replyModel: reply),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}(),
|
||||
),
|
||||
),
|
||||
if (showInput)
|
||||
Obx(
|
||||
() => CommentFootView(
|
||||
isSending: logic.isSendingMsg.value,
|
||||
onComment: (isSend) =>
|
||||
logic.readyReplyComment(null, isSend: isSend),
|
||||
textCtr: logic.commentController,
|
||||
imgPath: logic.selectedImagePath.value,
|
||||
onImgChange: (value) => logic.selectedImagePath.value = value,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
global: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user