mod: 搜索页跳转

This commit is contained in:
guozhigq
2024-01-07 20:50:15 +08:00
parent 042a0a848d
commit e8f7995b32
3 changed files with 117 additions and 132 deletions

View File

@ -161,7 +161,7 @@ class UserInfoWidget extends StatelessWidget {
Widget build(BuildContext context) {
return Row(
children: [
const Expanded(child: SearchPage()),
const SearchBar(),
if (userLogin.value) ...[
const SizedBox(width: 4),
ClipRect(
@ -199,7 +199,7 @@ class UserInfoWidget extends StatelessWidget {
)
],
)
: DefaultUser(callback: () => callback),
: DefaultUser(callback: () => callback!()),
),
],
);
@ -336,3 +336,50 @@ class CustomChip extends StatelessWidget {
);
}
}
class SearchBar extends StatelessWidget {
const SearchBar({super.key});
@override
Widget build(BuildContext context) {
final SSearchController searchController = Get.put(SSearchController());
final ColorScheme colorScheme = Theme.of(context).colorScheme;
return Expanded(
child: Container(
width: 250,
height: 44,
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25),
),
child: Material(
color: colorScheme.onSecondaryContainer.withOpacity(0.05),
child: InkWell(
splashColor: colorScheme.primaryContainer.withOpacity(0.3),
onTap: () => Get.toNamed('/search'),
child: Row(
children: [
const SizedBox(width: 14),
Icon(
Icons.search_outlined,
color: colorScheme.onSecondaryContainer,
),
const SizedBox(width: 10),
Expanded(
child: Obx(
() => Text(
searchController.defaultSearch.value,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: colorScheme.outline),
),
),
),
],
),
),
),
),
);
}
}

View File

@ -20,7 +20,7 @@ class SSearchController extends GetxController {
final _debouncer =
Debouncer(delay: const Duration(milliseconds: 200)); // 设置延迟时间
String hintText = '搜索';
RxString defaultSearch = '输入关键词搜索'.obs;
RxString defaultSearch = ''.obs;
Box setting = GStrorage.setting;
bool enableHotKey = true;

View File

@ -1,6 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:animations/animations.dart';
import 'package:get/get.dart';
import 'package:pilipala/common/widgets/http_error.dart';
import 'controller.dart';
@ -42,63 +41,6 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
@override
Widget build(BuildContext context) {
return OpenContainer(
closedElevation: 0,
openElevation: 0,
onClosed: (_) => _searchController.onClear(),
openColor: Theme.of(context).colorScheme.background,
middleColor: Theme.of(context).colorScheme.background,
closedColor: Colors.transparent,
closedShape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(30.0))),
openShape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(30.0))),
closedBuilder: (BuildContext context, VoidCallback openContainer) {
return Container(
width: 250,
height: 44,
clipBehavior: Clip.hardEdge,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(25)),
),
child: Material(
color: Theme.of(context)
.colorScheme
.onSecondaryContainer
.withOpacity(0.05),
child: InkWell(
splashColor: Theme.of(context)
.colorScheme
.primaryContainer
.withOpacity(0.3),
onTap: openContainer,
child: Row(
children: [
const SizedBox(width: 14),
Icon(
Icons.search_outlined,
color: Theme.of(context).colorScheme.onSecondaryContainer,
),
const SizedBox(width: 10),
Expanded(
child: Obx(
() => Text(
_searchController.defaultSearch.value,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Theme.of(context).colorScheme.outline,
),
),
),
),
],
),
),
),
);
},
openBuilder: (BuildContext context, VoidCallback _) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
@ -110,11 +52,9 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
),
titleSpacing: 0,
actions: [
Hero(
tag: 'searchTag',
child: IconButton(
IconButton(
onPressed: () => _searchController.submit(),
icon: const Icon(CupertinoIcons.search, size: 22)),
icon: const Icon(CupertinoIcons.search, size: 22),
),
const SizedBox(width: 10)
],
@ -150,15 +90,14 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
// 热搜
Visibility(
visible: _searchController.enableHotKey,
child: hotSearch(_searchController)),
child: hotSearch(_searchController),
),
// 搜索历史
_history()
],
),
),
);
},
);
}
Widget _searchSuggest() {
@ -301,16 +240,14 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
],
),
),
// if (_searchController.historyList.isNotEmpty)
Obx(() => Wrap(
Obx(
() => Wrap(
spacing: 8,
runSpacing: 8,
direction: Axis.horizontal,
textDirection: TextDirection.ltr,
children: [
for (int i = 0;
i < _searchController.historyList.length;
i++)
for (int i = 0; i < _searchController.historyList.length; i++)
SearchText(
searchText: _searchController.historyList[i],
searchTextIdx: i,
@ -319,7 +256,8 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
_searchController.onLongSelect(value),
)
],
)),
),
),
],
),
),