opt: reply2reply: sort widget

This commit is contained in:
bggRGjQaUbCoE
2024-10-13 17:14:20 +08:00
parent 88a09cd1f4
commit bdebf56f28
2 changed files with 76 additions and 45 deletions

View File

@@ -163,7 +163,7 @@ class VideoReplyReplyController extends CommonController
mode.value = mode.value == Mode.MAIN_LIST_HOT
? Mode.MAIN_LIST_TIME
: Mode.MAIN_LIST_HOT;
loadingState.value = LoadingState.loading();
// loadingState.value = LoadingState.loading();
onRefresh();
}
}

View File

@@ -39,6 +39,7 @@ class VideoReplyReplyPanel extends StatefulWidget {
class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
late VideoReplyReplyController _videoReplyReplyController;
late final _savedReplies = {};
final itemPositionsListener = ItemPositionsListener.create();
@override
void initState() {
@@ -64,6 +65,27 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
super.dispose();
}
Widget get _header => ValueListenableBuilder<Iterable<ItemPosition>>(
valueListenable: itemPositionsListener.itemPositions,
builder: (context, positions, child) {
int min = -1;
if (positions.isNotEmpty) {
min = positions
.where((ItemPosition position) => position.itemTrailingEdge > 0)
.reduce((ItemPosition min, ItemPosition position) =>
position.itemTrailingEdge < min.itemTrailingEdge
? position
: min)
.index;
}
return widget.firstFloor == null
? _sortWidget
: min >= 2
? _sortWidget
: const SizedBox.shrink();
},
);
@override
Widget build(BuildContext context) {
return Container(
@@ -98,50 +120,59 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
await _videoReplyReplyController.onRefresh();
},
child: Obx(
() => ScrollablePositionedList.builder(
itemCount:
_itemCount(_videoReplyReplyController.loadingState.value),
itemScrollController:
_videoReplyReplyController.itemScrollCtr,
physics: const AlwaysScrollableScrollPhysics(),
itemBuilder: (_, index) {
if (widget.firstFloor != null) {
if (index == 0) {
return ReplyItemGrpc(
replyItem: widget.firstFloor!,
replyLevel: '2',
showReplyRow: false,
replyType: widget.replyType,
needDivider: false,
onReply: () {
_onReply(widget.firstFloor!);
},
upMid: _videoReplyReplyController.upMid,
);
} else if (index == 1) {
return Divider(
height: 20,
color:
Theme.of(context).dividerColor.withOpacity(0.1),
thickness: 6,
);
} else if (index == 2) {
return _sortWidget;
} else {
return Obx(() => _buildBody(
_videoReplyReplyController.loadingState.value,
index - 3));
}
} else {
if (index == 0) {
return _sortWidget;
} else {
return Obx(() => _buildBody(
_videoReplyReplyController.loadingState.value,
index - 1));
}
}
},
() => Stack(
children: [
ScrollablePositionedList.builder(
itemPositionsListener: itemPositionsListener,
itemCount: _itemCount(
_videoReplyReplyController.loadingState.value),
itemScrollController:
_videoReplyReplyController.itemScrollCtr,
physics: const AlwaysScrollableScrollPhysics(),
itemBuilder: (_, index) {
if (widget.firstFloor != null) {
if (index == 0) {
return ReplyItemGrpc(
replyItem: widget.firstFloor!,
replyLevel: '2',
showReplyRow: false,
replyType: widget.replyType,
needDivider: false,
onReply: () {
_onReply(widget.firstFloor!);
},
upMid: _videoReplyReplyController.upMid,
);
} else if (index == 1) {
return Divider(
height: 20,
color: Theme.of(context)
.dividerColor
.withOpacity(0.1),
thickness: 6,
);
} else if (index == 2) {
return _sortWidget;
} else {
return Obx(() => _buildBody(
_videoReplyReplyController.loadingState.value,
index - 3));
}
} else {
if (index == 0) {
return _sortWidget;
} else {
return Obx(() => _buildBody(
_videoReplyReplyController.loadingState.value,
index - 1));
}
}
},
),
if (_videoReplyReplyController.loadingState.value
is Success)
_header,
],
),
),
),