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

View File

@ -54,4 +54,15 @@ class BangumiController extends GetxController {
} else {} } else {}
return result; 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, dividerColor: Colors.transparent,
unselectedLabelColor: unselectedLabelColor:
Theme.of(context).colorScheme.outline, Theme.of(context).colorScheme.outline,
onTap: (value) => onTap: (value) {
{feedBack(), _homeController.initialIndex = 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, currentIndex: selectedIndex,
// type: BottomNavigationBarType.shifting, // type: BottomNavigationBarType.shifting,
selectedItemColor: Theme.of(context).colorScheme.primary, selectedItemColor: Theme.of(context).colorScheme.primary,
unselectedItemColor: unselectedItemColor: Theme.of(context).colorScheme.outline,
Theme.of(context).colorScheme.onSurfaceVariant,
selectedFontSize: 12.4, selectedFontSize: 12.4,
onTap: (value) => setIndex(value), onTap: (value) => setIndex(value),
items: [ items: [

View File

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

View File

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

View File

@ -170,9 +170,9 @@ flutter:
- family: Jura-Bold - family: Jura-Bold
fonts: fonts:
- asset: assets/fonts/Jura-Bold.ttf - asset: assets/fonts/Jura-Bold.ttf
- family: HarmonyOS # - family: HarmonyOS
fonts: # fonts:
- asset: assets/fonts/HarmonyOS_Sans_SC_Regular.ttf # - asset: assets/fonts/HarmonyOS_Sans_SC_Regular.ttf
# For details regarding fonts from package dependencies, # For details regarding fonts from package dependencies,