feat: 合集列表自动跳转指定index

This commit is contained in:
guozhigq
2023-12-16 23:11:24 +08:00
parent 52ab78f332
commit e9a356c483
2 changed files with 158 additions and 106 deletions

View File

@ -27,6 +27,7 @@ class _PagesPanelState extends State<PagesPanel> {
late int currentIndex; late int currentIndex;
String heroTag = Get.arguments['heroTag']; String heroTag = Get.arguments['heroTag'];
late VideoDetailController _videoDetailController; late VideoDetailController _videoDetailController;
final ScrollController _scrollController = ScrollController();
@override @override
void initState() { void initState() {
@ -50,6 +51,12 @@ class _PagesPanelState extends State<PagesPanel> {
setState(() {}); setState(() {});
} }
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(
@ -80,23 +87,33 @@ class _PagesPanelState extends State<PagesPanel> {
onPressed: () { onPressed: () {
showBottomSheet( showBottomSheet(
context: context, context: context,
builder: (_) => Container( builder: (BuildContext context) {
return StatefulBuilder(builder:
(BuildContext context, StateSetter setState) {
WidgetsBinding.instance
.addPostFrameCallback((_) async {
await Future.delayed(
const Duration(milliseconds: 200));
_scrollController.jumpTo(currentIndex * 56);
});
return Container(
height: widget.sheetHeight, height: widget.sheetHeight,
color: Theme.of(context).colorScheme.background, color: Theme.of(context).colorScheme.background,
child: Column( child: Column(
children: [ children: [
Container( Container(
height: 45, height: 45,
padding: padding: const EdgeInsets.only(
const EdgeInsets.only(left: 14, right: 14), left: 14, right: 14),
child: Row( child: Row(
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment.spaceBetween, MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
'合集(${episodes.length}', '合集(${episodes.length}',
style: style: Theme.of(context)
Theme.of(context).textTheme.titleMedium, .textTheme
.titleMedium,
), ),
IconButton( IconButton(
icon: const Icon(Icons.close), icon: const Icon(Icons.close),
@ -114,29 +131,36 @@ class _PagesPanelState extends State<PagesPanel> {
Expanded( Expanded(
child: Material( child: Material(
child: ListView.builder( child: ListView.builder(
controller: _scrollController,
itemCount: episodes.length, itemCount: episodes.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
return InkWell( return ListTile(
onTap: () { onTap: () {
changeFucCall(episodes[index], index); changeFucCall(
episodes[index], index);
Get.back(); Get.back();
}, },
child: Padding( dense: false,
padding: const EdgeInsets.only( leading: index == currentIndex
top: 10, ? Image.asset(
bottom: 10, 'assets/images/live.gif',
left: 15, color: Theme.of(context)
right: 15), .colorScheme
child: Text( .primary,
height: 12,
)
: null,
title: Text(
episodes[index].pagePart!, episodes[index].pagePart!,
style: TextStyle( style: TextStyle(
fontSize: 14,
color: index == currentIndex color: index == currentIndex
? Theme.of(context) ? Theme.of(context)
.colorScheme .colorScheme
.primary .primary
: Theme.of(context) : Theme.of(context)
.colorScheme .colorScheme
.onSurface), .onSurface,
), ),
), ),
); );
@ -146,7 +170,9 @@ class _PagesPanelState extends State<PagesPanel> {
), ),
], ],
), ),
), );
});
},
); );
}, },
child: Text( child: Text(

View File

@ -28,6 +28,7 @@ class _SeasonPanelState extends State<SeasonPanel> {
late int currentIndex; late int currentIndex;
String heroTag = Get.arguments['heroTag']; String heroTag = Get.arguments['heroTag'];
late VideoDetailController _videoDetailController; late VideoDetailController _videoDetailController;
final ScrollController _scrollController = ScrollController();
@override @override
void initState() { void initState() {
@ -73,6 +74,12 @@ class _SeasonPanelState extends State<SeasonPanel> {
setState(() {}); setState(() {});
} }
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Builder(builder: (context) { return Builder(builder: (context) {
@ -90,7 +97,14 @@ class _SeasonPanelState extends State<SeasonPanel> {
child: InkWell( child: InkWell(
onTap: () => showBottomSheet( onTap: () => showBottomSheet(
context: context, context: context,
builder: (_) => Container( builder: (BuildContext context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
await Future.delayed(const Duration(milliseconds: 200));
_scrollController.jumpTo(currentIndex * 56);
});
return Container(
height: widget.sheetHeight, height: widget.sheetHeight,
color: Theme.of(context).colorScheme.background, color: Theme.of(context).colorScheme.background,
child: Column( child: Column(
@ -114,29 +128,39 @@ class _SeasonPanelState extends State<SeasonPanel> {
), ),
Divider( Divider(
height: 1, height: 1,
color: Theme.of(context).dividerColor.withOpacity(0.1), color:
Theme.of(context).dividerColor.withOpacity(0.1),
), ),
Expanded( Expanded(
child: Material( child: Material(
child: ListView.builder( child: ListView.builder(
controller: _scrollController,
itemCount: episodes.length, itemCount: episodes.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
return InkWell( return ListTile(
onTap: () => onTap: () =>
changeFucCall(episodes[index], index), changeFucCall(episodes[index], index),
child: Padding( dense: false,
padding: const EdgeInsets.only( leading: index == currentIndex
top: 10, bottom: 10, left: 15, right: 15), ? Image.asset(
child: Text( 'assets/images/live.gif',
color: Theme.of(context)
.colorScheme
.primary,
height: 12,
)
: null,
title: Text(
episodes[index].title!, episodes[index].title!,
style: TextStyle( style: TextStyle(
fontSize: 14,
color: index == currentIndex color: index == currentIndex
? Theme.of(context) ? Theme.of(context)
.colorScheme .colorScheme
.primary .primary
: Theme.of(context) : Theme.of(context)
.colorScheme .colorScheme
.onSurface), .onSurface,
), ),
), ),
); );
@ -146,7 +170,9 @@ class _SeasonPanelState extends State<SeasonPanel> {
), ),
], ],
), ),
), );
});
},
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.fromLTRB(8, 12, 8, 12), padding: const EdgeInsets.fromLTRB(8, 12, 8, 12),