mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-27 03:28:40 +00:00
feat: vertical tabbar
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -2,9 +2,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:PiliPlus/models/common/rank_type.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/pages/main/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';
|
||||
|
||||
@@ -21,27 +19,6 @@ class RankController extends GetxController
|
||||
@override
|
||||
ScrollController get scrollController => controller.scrollController;
|
||||
|
||||
final _mainCtr = Get.find<MainController>();
|
||||
|
||||
final tabScrollController = ScrollController();
|
||||
|
||||
void scrollToCurrentIndex(double tabHeight, int index) {
|
||||
final position = tabScrollController.position;
|
||||
final offset = clampDouble(
|
||||
(tabHeight * (2 * index + 1) - position.viewportDimension) / 2.0 +
|
||||
(_mainCtr.useBottomNav && (_mainCtr.showBottomBar?.value ?? true)
|
||||
? 80.0
|
||||
: 0.0),
|
||||
position.minScrollExtent,
|
||||
position.maxScrollExtent,
|
||||
);
|
||||
tabScrollController.animateTo(
|
||||
offset,
|
||||
duration: kTabScrollDuration,
|
||||
curve: Curves.ease,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -51,7 +28,6 @@ class RankController extends GetxController
|
||||
@override
|
||||
void onClose() {
|
||||
tabController.dispose();
|
||||
tabScrollController.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPlus/common/widgets/flutter/vertical_tabs.dart';
|
||||
import 'package:PiliPlus/models/common/rank_type.dart';
|
||||
import 'package:PiliPlus/pages/rank/controller.dart';
|
||||
import 'package:PiliPlus/pages/rank/zone/view.dart';
|
||||
@@ -43,76 +44,24 @@ class _RankPageState extends State<RankPage>
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_tabHeight = MediaQuery.textScalerOf(context).scale(21) + 14;
|
||||
}
|
||||
|
||||
late double _tabHeight;
|
||||
|
||||
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 SizedBox(
|
||||
height: _tabHeight,
|
||||
child: Material(
|
||||
color: isCurr
|
||||
? theme.colorScheme.onInverseSurface
|
||||
: theme.colorScheme.surface,
|
||||
child: InkWell(
|
||||
onTap: isCurr
|
||||
? _rankController.animateToTop
|
||||
: () => _rankController
|
||||
..tabIndex.value = index
|
||||
..tabController.animateTo(index)
|
||||
..scrollToCurrentIndex(_tabHeight, index),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (isCurr)
|
||||
Container(
|
||||
width: 3,
|
||||
height: double.infinity,
|
||||
color: theme.colorScheme.primary,
|
||||
)
|
||||
else
|
||||
const SizedBox(width: 3),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
padding: const .symmetric(vertical: 7),
|
||||
child: Text(
|
||||
item.label,
|
||||
style: isCurr
|
||||
? TextStyle(
|
||||
fontSize: 15,
|
||||
color: theme.colorScheme.primary,
|
||||
)
|
||||
: const TextStyle(fontSize: 15),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
return VerticalTabBar(
|
||||
dividerWidth: 0,
|
||||
isScrollable: true,
|
||||
indicatorWeight: 3,
|
||||
indicatorSize: .tab,
|
||||
controller: _rankController.tabController,
|
||||
padding: .only(bottom: MediaQuery.paddingOf(context).bottom + 105),
|
||||
tabs: RankType.values.map((e) => VerticalTab(text: e.label)).toList(),
|
||||
onTap: (index) {
|
||||
if (!_rankController.tabController.indexIsChanging) {
|
||||
_rankController.animateToTop();
|
||||
} else {
|
||||
_rankController
|
||||
..tabIndex.value = index
|
||||
..tabController.animateTo(index);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user