mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-29 06:45:54 +08:00
scroll to current rank
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:PiliPlus/models/common/rank_type.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/pages/rank/zone/controller.dart';
|
||||
import 'package:flutter/foundation.dart' show clampDouble;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
@@ -19,6 +20,22 @@ class RankController extends GetxController
|
||||
@override
|
||||
ScrollController get scrollController => controller.scrollController;
|
||||
|
||||
final tabScrollController = ScrollController();
|
||||
|
||||
void scrollToCurrentIndex(double tabHeight, int index) {
|
||||
final position = tabScrollController.position;
|
||||
final offset = clampDouble(
|
||||
(tabHeight * (2 * index + 1) - position.viewportDimension) / 2.0 + 80.0,
|
||||
position.minScrollExtent,
|
||||
position.maxScrollExtent,
|
||||
);
|
||||
tabScrollController.animateTo(
|
||||
offset,
|
||||
duration: kTabScrollDuration,
|
||||
curve: Curves.ease,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -28,6 +45,7 @@ class RankController extends GetxController
|
||||
@override
|
||||
void onClose() {
|
||||
tabController.dispose();
|
||||
tabScrollController.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,18 +43,22 @@ class _RankPageState extends State<RankPage>
|
||||
);
|
||||
}
|
||||
|
||||
static const double _tabHeight = 35.0;
|
||||
|
||||
Widget _buildTab(ThemeData theme) {
|
||||
return SizedBox(
|
||||
width: 64,
|
||||
child: Obx(() {
|
||||
final tabIndex = _rankController.tabIndex.value;
|
||||
return ListView.builder(
|
||||
controller: _rankController.tabScrollController,
|
||||
padding: .only(bottom: MediaQuery.paddingOf(context).bottom + 105),
|
||||
itemCount: RankType.values.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = RankType.values[index];
|
||||
final isCurr = index == tabIndex;
|
||||
return IntrinsicHeight(
|
||||
return SizedBox(
|
||||
height: _tabHeight,
|
||||
child: Material(
|
||||
color: isCurr
|
||||
? theme.colorScheme.onInverseSurface
|
||||
@@ -64,7 +68,8 @@ class _RankPageState extends State<RankPage>
|
||||
? _rankController.animateToTop
|
||||
: () => _rankController
|
||||
..tabIndex.value = index
|
||||
..tabController.animateTo(index),
|
||||
..tabController.animateTo(index)
|
||||
..scrollToCurrentIndex(_tabHeight, index),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
|
||||
Reference in New Issue
Block a user