mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-30 23:58:13 +08:00
opt: initialScrollIndex (#1018)
This commit is contained in:
committed by
GitHub
parent
629be129ff
commit
1943b65788
@@ -50,34 +50,15 @@ class MediaListPanel extends CommonCollapseSlidePage {
|
||||
|
||||
class _MediaListPanelState
|
||||
extends CommonCollapseSlidePageState<MediaListPanel> {
|
||||
final _scrollController = ItemScrollController();
|
||||
late RxBool desc;
|
||||
late final int _index;
|
||||
late final RxBool desc = widget.desc.obs;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
desc = widget.desc.obs;
|
||||
}
|
||||
|
||||
@override
|
||||
void init() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
int index = widget.mediaList.indexWhere(
|
||||
(item) => item.bvid == widget.getBvId(),
|
||||
);
|
||||
if (index > 0) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
try {
|
||||
_scrollController.jumpTo(index: index);
|
||||
} catch (_) {}
|
||||
});
|
||||
}
|
||||
setState(() {
|
||||
isInit = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
final bvid = widget.getBvId();
|
||||
final bvIndex = widget.mediaList.indexWhere((item) => item.bvid == bvid);
|
||||
_index = bvIndex == -1 ? 0 : bvIndex;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -142,9 +123,9 @@ class _MediaListPanelState
|
||||
() {
|
||||
final showDelBtn = widget.onDelete != null && widget.mediaList.length > 1;
|
||||
return ScrollablePositionedList.separated(
|
||||
itemScrollController: _scrollController,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
itemCount: widget.mediaList.length,
|
||||
initialScrollIndex: _index,
|
||||
padding: EdgeInsets.only(
|
||||
top: 7,
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 80,
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:PiliPlus/pages/video/reply_new/view.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
import 'package:PiliPlus/utils/request_utils.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:fixnum/fixnum.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get_navigation/src/dialog/dialog_route.dart';
|
||||
@@ -72,26 +73,26 @@ class VideoReplyReplyController extends ReplyController
|
||||
firstFloor = data.root;
|
||||
}
|
||||
if (id != null) {
|
||||
index = data.root.replies.indexWhere((item) => item.id.toInt() == id);
|
||||
if (index == -1) {
|
||||
index = null;
|
||||
} else {
|
||||
final id64 = Int64(id!);
|
||||
final index = data.root.replies.indexWhere((item) => item.id == id64);
|
||||
if (index != -1) {
|
||||
this.index = index;
|
||||
controller = AnimationController(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
vsync: this,
|
||||
);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
if (index != null) {
|
||||
try {
|
||||
itemScrollCtr.jumpTo(
|
||||
index: hasRoot ? index! + 3 : index! + 1,
|
||||
alignment: 0.25,
|
||||
);
|
||||
await Future.delayed(const Duration(milliseconds: 800));
|
||||
await controller?.forward();
|
||||
index = null;
|
||||
} catch (_) {}
|
||||
}
|
||||
try {
|
||||
itemScrollCtr.jumpTo(
|
||||
index: hasRoot ? index + 3 : index + 1,
|
||||
alignment: 0.25,
|
||||
);
|
||||
await Future.delayed(
|
||||
const Duration(milliseconds: 800),
|
||||
controller?.forward,
|
||||
);
|
||||
this.index = null;
|
||||
} catch (_) {}
|
||||
});
|
||||
}
|
||||
id = null;
|
||||
|
||||
@@ -321,6 +321,7 @@ class _VideoReplyReplyPanelState
|
||||
),
|
||||
);
|
||||
} else {
|
||||
final child = _replyItem(response[index], index);
|
||||
if (_controller.index != null && _controller.index == index) {
|
||||
colorAnimation ??= ColorTween(
|
||||
begin: theme.colorScheme.onInverseSurface,
|
||||
@@ -328,17 +329,17 @@ class _VideoReplyReplyPanelState
|
||||
).animate(_controller.controller!);
|
||||
return AnimatedBuilder(
|
||||
animation: colorAnimation!,
|
||||
builder: (context, child) {
|
||||
builder: (context, _) {
|
||||
return ColoredBox(
|
||||
color:
|
||||
colorAnimation!.value ??
|
||||
theme.colorScheme.onInverseSurface,
|
||||
child: _replyItem(response[index], index),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
return _replyItem(response[index], index);
|
||||
return child;
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user