fix: 退出搜索页面控制器未销毁
This commit is contained in:
@ -5,6 +5,7 @@ import 'package:get/get.dart';
|
|||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:pilipala/models/common/tab_type.dart';
|
import 'package:pilipala/models/common/tab_type.dart';
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
import '../../http/index.dart';
|
||||||
|
|
||||||
class HomeController extends GetxController with GetTickerProviderStateMixin {
|
class HomeController extends GetxController with GetTickerProviderStateMixin {
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
@ -24,6 +25,7 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
|
|||||||
late bool hideSearchBar;
|
late bool hideSearchBar;
|
||||||
late List defaultTabs;
|
late List defaultTabs;
|
||||||
late List<String> tabbarSort;
|
late List<String> tabbarSort;
|
||||||
|
RxString defaultSearch = ''.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -35,6 +37,9 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
|
|||||||
setTabConfig();
|
setTabConfig();
|
||||||
hideSearchBar =
|
hideSearchBar =
|
||||||
setting.get(SettingBoxKey.hideSearchBar, defaultValue: true);
|
setting.get(SettingBoxKey.hideSearchBar, defaultValue: true);
|
||||||
|
if (setting.get(SettingBoxKey.enableSearchWord, defaultValue: true)) {
|
||||||
|
searchDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRefresh() {
|
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'];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||||
import 'package:pilipala/pages/mine/index.dart';
|
import 'package:pilipala/pages/mine/index.dart';
|
||||||
import 'package:pilipala/pages/search/index.dart';
|
|
||||||
import 'package:pilipala/utils/feed_back.dart';
|
import 'package:pilipala/utils/feed_back.dart';
|
||||||
import './controller.dart';
|
import './controller.dart';
|
||||||
|
|
||||||
@ -144,6 +143,7 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
padding: EdgeInsets.fromLTRB(14, top + 6, 14, 0),
|
padding: EdgeInsets.fromLTRB(14, top + 6, 14, 0),
|
||||||
child: UserInfoWidget(
|
child: UserInfoWidget(
|
||||||
top: top,
|
top: top,
|
||||||
|
ctr: ctr,
|
||||||
userLogin: isUserLoggedIn,
|
userLogin: isUserLoggedIn,
|
||||||
userFace: ctr?.userFace.value,
|
userFace: ctr?.userFace.value,
|
||||||
callback: () => callback!(),
|
callback: () => callback!(),
|
||||||
@ -162,18 +162,20 @@ class UserInfoWidget extends StatelessWidget {
|
|||||||
required this.userLogin,
|
required this.userLogin,
|
||||||
required this.userFace,
|
required this.userFace,
|
||||||
required this.callback,
|
required this.callback,
|
||||||
|
required this.ctr,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final double top;
|
final double top;
|
||||||
final RxBool userLogin;
|
final RxBool userLogin;
|
||||||
final String? userFace;
|
final String? userFace;
|
||||||
final VoidCallback? callback;
|
final VoidCallback? callback;
|
||||||
|
final HomeController? ctr;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
const SearchBar(),
|
SearchBar(ctr: ctr),
|
||||||
if (userLogin.value) ...[
|
if (userLogin.value) ...[
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
ClipRect(
|
ClipRect(
|
||||||
@ -335,11 +337,15 @@ class CustomChip extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class SearchBar extends StatelessWidget {
|
class SearchBar extends StatelessWidget {
|
||||||
const SearchBar({super.key});
|
const SearchBar({
|
||||||
|
Key? key,
|
||||||
|
required this.ctr,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
final HomeController? ctr;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final SSearchController searchController = Get.put(SSearchController());
|
|
||||||
final ColorScheme colorScheme = Theme.of(context).colorScheme;
|
final ColorScheme colorScheme = Theme.of(context).colorScheme;
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: Container(
|
child: Container(
|
||||||
@ -353,7 +359,10 @@ class SearchBar extends StatelessWidget {
|
|||||||
color: colorScheme.onSecondaryContainer.withOpacity(0.05),
|
color: colorScheme.onSecondaryContainer.withOpacity(0.05),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
splashColor: colorScheme.primaryContainer.withOpacity(0.3),
|
splashColor: colorScheme.primaryContainer.withOpacity(0.3),
|
||||||
onTap: () => Get.toNamed('/search'),
|
onTap: () => Get.toNamed(
|
||||||
|
'/search',
|
||||||
|
parameters: {'hintText': ctr!.defaultSearch.value},
|
||||||
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(width: 14),
|
const SizedBox(width: 14),
|
||||||
@ -362,16 +371,14 @@ class SearchBar extends StatelessWidget {
|
|||||||
color: colorScheme.onSecondaryContainer,
|
color: colorScheme.onSecondaryContainer,
|
||||||
),
|
),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
Expanded(
|
Obx(
|
||||||
child: Obx(
|
|
||||||
() => Text(
|
() => Text(
|
||||||
searchController.defaultSearch.value,
|
ctr!.defaultSearch.value,
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: TextStyle(color: colorScheme.outline),
|
style: TextStyle(color: colorScheme.outline),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:get/get_rx/src/rx_workers/utils/debouncer.dart';
|
import 'package:get/get_rx/src/rx_workers/utils/debouncer.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:pilipala/http/index.dart';
|
|
||||||
import 'package:pilipala/http/search.dart';
|
import 'package:pilipala/http/search.dart';
|
||||||
import 'package:pilipala/models/search/hot.dart';
|
import 'package:pilipala/models/search/hot.dart';
|
||||||
import 'package:pilipala/models/search/suggest.dart';
|
import 'package:pilipala/models/search/suggest.dart';
|
||||||
@ -27,9 +26,6 @@ class SSearchController extends GetxController {
|
|||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
if (setting.get(SettingBoxKey.enableSearchWord, defaultValue: true)) {
|
|
||||||
searchDefault();
|
|
||||||
}
|
|
||||||
// 其他页面跳转过来
|
// 其他页面跳转过来
|
||||||
if (Get.parameters.keys.isNotEmpty) {
|
if (Get.parameters.keys.isNotEmpty) {
|
||||||
if (Get.parameters['keyword'] != null) {
|
if (Get.parameters['keyword'] != null) {
|
||||||
@ -130,12 +126,4 @@ class SSearchController extends GetxController {
|
|||||||
historyList.refresh();
|
historyList.refresh();
|
||||||
histiryWord.put('cacheList', []);
|
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'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user