From d1bacf89504d96e72f407c61733dee6359deea50 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 27 Jan 2024 00:24:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=80=E5=87=BA=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=8E=A7=E5=88=B6=E5=99=A8=E6=9C=AA=E9=94=80?= =?UTF-8?q?=E6=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/home/controller.dart | 12 ++++++++++++ lib/pages/home/view.dart | 33 +++++++++++++++++++------------- lib/pages/search/controller.dart | 12 ------------ 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/lib/pages/home/controller.dart b/lib/pages/home/controller.dart index 64510ee14..e6fafba63 100644 --- a/lib/pages/home/controller.dart +++ b/lib/pages/home/controller.dart @@ -5,6 +5,7 @@ import 'package:get/get.dart'; import 'package:hive/hive.dart'; import 'package:pilipala/models/common/tab_type.dart'; import 'package:pilipala/utils/storage.dart'; +import '../../http/index.dart'; class HomeController extends GetxController with GetTickerProviderStateMixin { bool flag = false; @@ -24,6 +25,7 @@ class HomeController extends GetxController with GetTickerProviderStateMixin { late bool hideSearchBar; late List defaultTabs; late List tabbarSort; + RxString defaultSearch = ''.obs; @override void onInit() { @@ -35,6 +37,9 @@ class HomeController extends GetxController with GetTickerProviderStateMixin { setTabConfig(); hideSearchBar = setting.get(SettingBoxKey.hideSearchBar, defaultValue: true); + if (setting.get(SettingBoxKey.enableSearchWord, defaultValue: true)) { + searchDefault(); + } } void onRefresh() { @@ -94,4 +99,11 @@ class HomeController extends GetxController with GetTickerProviderStateMixin { } }); } + + void searchDefault() async { + var res = await Request().get(Api.searchDefault); + if (res.data['code'] == 0) { + defaultSearch.value = res.data['data']['name']; + } + } } diff --git a/lib/pages/home/view.dart b/lib/pages/home/view.dart index c31460fb0..ce7b46c61 100644 --- a/lib/pages/home/view.dart +++ b/lib/pages/home/view.dart @@ -5,7 +5,6 @@ import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:pilipala/common/widgets/network_img_layer.dart'; import 'package:pilipala/pages/mine/index.dart'; -import 'package:pilipala/pages/search/index.dart'; import 'package:pilipala/utils/feed_back.dart'; import './controller.dart'; @@ -144,6 +143,7 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { padding: EdgeInsets.fromLTRB(14, top + 6, 14, 0), child: UserInfoWidget( top: top, + ctr: ctr, userLogin: isUserLoggedIn, userFace: ctr?.userFace.value, callback: () => callback!(), @@ -162,18 +162,20 @@ class UserInfoWidget extends StatelessWidget { required this.userLogin, required this.userFace, required this.callback, + required this.ctr, }) : super(key: key); final double top; final RxBool userLogin; final String? userFace; final VoidCallback? callback; + final HomeController? ctr; @override Widget build(BuildContext context) { return Row( children: [ - const SearchBar(), + SearchBar(ctr: ctr), if (userLogin.value) ...[ const SizedBox(width: 4), ClipRect( @@ -335,11 +337,15 @@ class CustomChip extends StatelessWidget { } class SearchBar extends StatelessWidget { - const SearchBar({super.key}); + const SearchBar({ + Key? key, + required this.ctr, + }) : super(key: key); + + final HomeController? ctr; @override Widget build(BuildContext context) { - final SSearchController searchController = Get.put(SSearchController()); final ColorScheme colorScheme = Theme.of(context).colorScheme; return Expanded( child: Container( @@ -353,7 +359,10 @@ class SearchBar extends StatelessWidget { color: colorScheme.onSecondaryContainer.withOpacity(0.05), child: InkWell( splashColor: colorScheme.primaryContainer.withOpacity(0.3), - onTap: () => Get.toNamed('/search'), + onTap: () => Get.toNamed( + '/search', + parameters: {'hintText': ctr!.defaultSearch.value}, + ), child: Row( children: [ const SizedBox(width: 14), @@ -362,14 +371,12 @@ class SearchBar extends StatelessWidget { color: colorScheme.onSecondaryContainer, ), const SizedBox(width: 10), - Expanded( - child: Obx( - () => Text( - searchController.defaultSearch.value, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: TextStyle(color: colorScheme.outline), - ), + Obx( + () => Text( + ctr!.defaultSearch.value, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle(color: colorScheme.outline), ), ), ], diff --git a/lib/pages/search/controller.dart b/lib/pages/search/controller.dart index 52a521e23..5ec1710a2 100644 --- a/lib/pages/search/controller.dart +++ b/lib/pages/search/controller.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:get/get_rx/src/rx_workers/utils/debouncer.dart'; import 'package:hive/hive.dart'; -import 'package:pilipala/http/index.dart'; import 'package:pilipala/http/search.dart'; import 'package:pilipala/models/search/hot.dart'; import 'package:pilipala/models/search/suggest.dart'; @@ -27,9 +26,6 @@ class SSearchController extends GetxController { @override void onInit() { super.onInit(); - if (setting.get(SettingBoxKey.enableSearchWord, defaultValue: true)) { - searchDefault(); - } // 其他页面跳转过来 if (Get.parameters.keys.isNotEmpty) { if (Get.parameters['keyword'] != null) { @@ -130,12 +126,4 @@ class SSearchController extends GetxController { historyList.refresh(); histiryWord.put('cacheList', []); } - - void searchDefault() async { - var res = await Request().get(Api.searchDefault); - if (res.data['code'] == 0) { - searchKeyWord.value = - hintText = defaultSearch.value = res.data['data']['name']; - } - } }