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.value = mode.value == Mode.MAIN_LIST_HOT
? Mode.MAIN_LIST_TIME ? Mode.MAIN_LIST_TIME
: Mode.MAIN_LIST_HOT; : Mode.MAIN_LIST_HOT;
loadingState.value = LoadingState.loading(); // loadingState.value = LoadingState.loading();
onRefresh(); onRefresh();
} }
} }

View File

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