mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
fix: home tab
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -12,7 +13,6 @@ import '../mine/view.dart';
|
||||
class HomeController extends GetxController with GetTickerProviderStateMixin {
|
||||
bool flag = true;
|
||||
late RxList tabs = [].obs;
|
||||
RxInt initialIndex = 1.obs;
|
||||
late TabController tabController;
|
||||
late List tabsCtrList;
|
||||
late List<Widget> tabsPageList;
|
||||
@@ -81,16 +81,11 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
|
||||
|
||||
tabs.value = defaultTabs;
|
||||
|
||||
if (tabbarSort.contains(TabType.rcmd.id)) {
|
||||
initialIndex.value = tabbarSort.indexOf(TabType.rcmd.id);
|
||||
} else {
|
||||
initialIndex.value = 0;
|
||||
}
|
||||
tabsCtrList = tabs.map((e) => e['ctr']).toList();
|
||||
tabsPageList = tabs.map<Widget>((e) => e['page']).toList();
|
||||
|
||||
tabController = TabController(
|
||||
initialIndex: initialIndex.value,
|
||||
initialIndex: max(0, tabbarSort.indexOf(TabType.rcmd.id)),
|
||||
length: tabs.length,
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:PiliPalaX/utils/extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -70,10 +71,9 @@ class _HomePageState extends State<HomePage>
|
||||
tabAlignment: TabAlignment.center,
|
||||
onTap: (value) {
|
||||
feedBack();
|
||||
if (_homeController.initialIndex.value == value) {
|
||||
if (_homeController.tabController.indexIsChanging.not) {
|
||||
_homeController.tabsCtrList[value]().animateToTop();
|
||||
}
|
||||
_homeController.initialIndex.value = value;
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -290,53 +290,53 @@ class DefaultUser extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class CustomTabs extends StatefulWidget {
|
||||
const CustomTabs({super.key});
|
||||
// class CustomTabs extends StatefulWidget {
|
||||
// const CustomTabs({super.key});
|
||||
|
||||
@override
|
||||
State<CustomTabs> createState() => _CustomTabsState();
|
||||
}
|
||||
// @override
|
||||
// State<CustomTabs> createState() => _CustomTabsState();
|
||||
// }
|
||||
|
||||
class _CustomTabsState extends State<CustomTabs> {
|
||||
final HomeController _homeController = Get.put(HomeController());
|
||||
// class _CustomTabsState extends State<CustomTabs> {
|
||||
// final HomeController _homeController = Get.put(HomeController());
|
||||
|
||||
void onTap(int index) {
|
||||
feedBack();
|
||||
if (_homeController.initialIndex.value == index) {
|
||||
_homeController.tabsCtrList[index]().animateToTop();
|
||||
}
|
||||
_homeController.initialIndex.value = index;
|
||||
_homeController.tabController.index = index;
|
||||
}
|
||||
// void onTap(int index) {
|
||||
// feedBack();
|
||||
// if (_homeController.initialIndex.value == index) {
|
||||
// _homeController.tabsCtrList[index]().animateToTop();
|
||||
// }
|
||||
// _homeController.initialIndex.value = index;
|
||||
// _homeController.tabController.index = index;
|
||||
// }
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: 44,
|
||||
margin: const EdgeInsets.only(top: 4),
|
||||
child: Obx(
|
||||
() => ListView.separated(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14.0),
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: _homeController.tabs.length,
|
||||
separatorBuilder: (BuildContext context, int index) {
|
||||
return const SizedBox(width: 10);
|
||||
},
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
String label = _homeController.tabs[index]['label'];
|
||||
return Obx(
|
||||
() => CustomChip(
|
||||
onTap: () => onTap(index),
|
||||
label: label,
|
||||
selected: index == _homeController.initialIndex.value,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Container(
|
||||
// height: 44,
|
||||
// margin: const EdgeInsets.only(top: 4),
|
||||
// child: Obx(
|
||||
// () => ListView.separated(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 14.0),
|
||||
// scrollDirection: Axis.horizontal,
|
||||
// itemCount: _homeController.tabs.length,
|
||||
// separatorBuilder: (BuildContext context, int index) {
|
||||
// return const SizedBox(width: 10);
|
||||
// },
|
||||
// itemBuilder: (BuildContext context, int index) {
|
||||
// String label = _homeController.tabs[index]['label'];
|
||||
// return Obx(
|
||||
// () => CustomChip(
|
||||
// onTap: () => onTap(index),
|
||||
// label: label,
|
||||
// selected: index == _homeController.initialIndex.value,
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
class CustomChip extends StatelessWidget {
|
||||
final Function onTap;
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'package:get/get.dart';
|
||||
|
||||
class SearchResultController extends GetxController {
|
||||
String? keyword;
|
||||
int tabIndex = 0;
|
||||
|
||||
RxList<int> count = List.generate(5, (_) => -1).toList().obs;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPalaX/utils/extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/models/common/search_type.dart';
|
||||
@@ -28,7 +29,6 @@ class _SearchResultPageState extends State<SearchResultPage>
|
||||
_tabController = TabController(
|
||||
vsync: this,
|
||||
length: SearchType.values.length,
|
||||
initialIndex: _searchResultController.tabIndex,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -101,14 +101,12 @@ class _SearchResultPageState extends State<SearchResultPage>
|
||||
unselectedLabelColor: Theme.of(context).colorScheme.outline,
|
||||
tabAlignment: TabAlignment.start,
|
||||
onTap: (index) {
|
||||
if (index == _searchResultController.tabIndex) {
|
||||
if (_tabController.indexIsChanging.not) {
|
||||
Get.find<SearchPanelController>(
|
||||
tag: SearchType.values[index].type +
|
||||
_searchResultController.keyword!)
|
||||
.animateToTop();
|
||||
}
|
||||
|
||||
_searchResultController.tabIndex = index;
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user