feat: 首页搜索页点击tab返回顶部

This commit is contained in:
guozhigq
2023-08-09 23:21:27 +08:00
parent 8a5a56cb15
commit d5943d88b0
8 changed files with 32 additions and 16 deletions

View File

@ -40,7 +40,7 @@ class MyApp extends StatelessWidget {
return GetMaterialApp(
title: 'PiLiPaLa',
theme: ThemeData(
fontFamily: 'HarmonyOS',
// fontFamily: 'HarmonyOS',
colorScheme: lightDynamic ??
ColorScheme.fromSeed(
seedColor: Colors.green,
@ -56,7 +56,7 @@ class MyApp extends StatelessWidget {
),
),
darkTheme: ThemeData(
fontFamily: 'HarmonyOS',
// fontFamily: 'HarmonyOS',
colorScheme: darkDynamic ??
ColorScheme.fromSeed(
seedColor: Colors.green,

View File

@ -54,4 +54,15 @@ class BangumiController extends GetxController {
} else {}
return result;
}
// 返回顶部并刷新
void animateToTop() async {
if (scrollController.offset >=
MediaQuery.of(Get.context!).size.height * 5) {
scrollController.jumpTo(0);
} else {
await scrollController.animateTo(0,
duration: const Duration(milliseconds: 500), curve: Curves.easeInOut);
}
}
}

View File

@ -100,8 +100,13 @@ class _HomePageState extends State<HomePage>
dividerColor: Colors.transparent,
unselectedLabelColor:
Theme.of(context).colorScheme.outline,
onTap: (value) =>
{feedBack(), _homeController.initialIndex = value},
onTap: (value) {
feedBack();
if (_homeController.initialIndex == value) {
_homeController.ctrList[value]().animateToTop();
}
_homeController.initialIndex = value;
},
),
),
),

View File

@ -142,8 +142,7 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
currentIndex: selectedIndex,
// type: BottomNavigationBarType.shifting,
selectedItemColor: Theme.of(context).colorScheme.primary,
unselectedItemColor:
Theme.of(context).colorScheme.onSurfaceVariant,
unselectedItemColor: Theme.of(context).colorScheme.outline,
selectedFontSize: 12.4,
onTap: (value) => setIndex(value),
items: [

View File

@ -25,7 +25,7 @@ class SearchPanel extends StatefulWidget {
class _SearchPanelState extends State<SearchPanel>
with AutomaticKeepAliveClientMixin {
late SearchPanelController? _searchPanelController;
late SearchPanelController _searchPanelController;
bool _isLoadingMore = false;
late Future _futureBuilderFuture;
@ -41,10 +41,9 @@ class _SearchPanelState extends State<SearchPanel>
keyword: widget.keyword,
searchType: widget.searchType,
),
tag: widget.searchType!.type + widget.tag!,
tag: widget.searchType!.type,
);
ScrollController scrollController =
_searchPanelController!.scrollController;
ScrollController scrollController = _searchPanelController.scrollController;
scrollController.addListener(() async {
if (scrollController.position.pixels >=
scrollController.position.maxScrollExtent - 100) {
@ -55,7 +54,7 @@ class _SearchPanelState extends State<SearchPanel>
}
}
});
_futureBuilderFuture = _searchPanelController!.onSearch();
_futureBuilderFuture = _searchPanelController.onSearch();
}
@override
@ -63,7 +62,7 @@ class _SearchPanelState extends State<SearchPanel>
super.build(context);
return RefreshIndicator(
onRefresh: () async {
await _searchPanelController!.onRefresh();
await _searchPanelController.onRefresh();
},
child: FutureBuilder(
future: _futureBuilderFuture,
@ -71,7 +70,7 @@ class _SearchPanelState extends State<SearchPanel>
if (snapshot.connectionState == ConnectionState.done) {
Map data = snapshot.data;
var ctr = _searchPanelController;
List list = ctr!.resultList;
List list = ctr.resultList;
if (data['status']) {
return Obx(() {
switch (widget.searchType) {

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pilipala/models/common/search_type.dart';
import 'package:pilipala/pages/rcmd/index.dart';
import 'package:pilipala/pages/searchPanel/index.dart';
import 'controller.dart';
@ -88,6 +89,7 @@ class _SearchResultPageState extends State<SearchResultPage>
tag: SearchType.values[index].type)
.animateToTop();
}
_searchResultController!.tabIndex = index;
},
),