2022-07-07 11:40:54 -07:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-02-27 11:45:12 -07:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/modules/search/providers/search_page_state.provider.dart';
|
|
|
|
|
2023-05-12 07:21:13 -07:00
|
|
|
class ImmichSearchBar extends HookConsumerWidget
|
|
|
|
implements PreferredSizeWidget {
|
|
|
|
const ImmichSearchBar({
|
2022-07-13 05:23:48 -07:00
|
|
|
Key? key,
|
|
|
|
required this.searchFocusNode,
|
|
|
|
required this.onSubmitted,
|
|
|
|
}) : super(key: key);
|
2022-03-02 15:44:24 -07:00
|
|
|
|
|
|
|
final FocusNode searchFocusNode;
|
|
|
|
final Function(String) onSubmitted;
|
2022-02-27 11:45:12 -07:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final searchTermController = useTextEditingController(text: "");
|
|
|
|
final isSearchEnabled = ref.watch(searchPageStateProvider).isSearchEnabled;
|
|
|
|
|
|
|
|
return AppBar(
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
leading: isSearchEnabled
|
|
|
|
? IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
searchFocusNode.unfocus();
|
|
|
|
ref.watch(searchPageStateProvider.notifier).disableSearch();
|
2022-03-02 15:44:24 -07:00
|
|
|
searchTermController.clear();
|
2022-02-27 11:45:12 -07:00
|
|
|
},
|
2022-07-13 05:23:48 -07:00
|
|
|
icon: const Icon(Icons.arrow_back_ios_rounded),
|
|
|
|
)
|
2023-03-28 08:34:06 -07:00
|
|
|
: const Icon(
|
|
|
|
Icons.search_rounded,
|
|
|
|
size: 20,
|
|
|
|
),
|
2022-02-27 11:45:12 -07:00
|
|
|
title: TextField(
|
|
|
|
controller: searchTermController,
|
|
|
|
focusNode: searchFocusNode,
|
|
|
|
autofocus: false,
|
|
|
|
onTap: () {
|
2022-03-02 15:44:24 -07:00
|
|
|
searchTermController.clear();
|
2022-02-27 11:43:29 -07:00
|
|
|
ref.watch(searchPageStateProvider.notifier).getSuggestedSearchTerms();
|
2022-02-27 11:45:12 -07:00
|
|
|
ref.watch(searchPageStateProvider.notifier).enableSearch();
|
2022-03-02 15:44:24 -07:00
|
|
|
ref.watch(searchPageStateProvider.notifier).setSearchTerm("");
|
|
|
|
|
2022-02-27 11:45:12 -07:00
|
|
|
searchFocusNode.requestFocus();
|
|
|
|
},
|
|
|
|
onSubmitted: (searchTerm) {
|
2022-03-02 15:44:24 -07:00
|
|
|
onSubmitted(searchTerm);
|
|
|
|
searchTermController.clear();
|
|
|
|
ref.watch(searchPageStateProvider.notifier).setSearchTerm("");
|
2022-02-27 11:45:12 -07:00
|
|
|
},
|
|
|
|
onChanged: (value) {
|
|
|
|
ref.watch(searchPageStateProvider.notifier).setSearchTerm(value);
|
|
|
|
},
|
2022-07-07 11:40:54 -07:00
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: 'search_bar_hint'.tr(),
|
2023-02-11 13:23:32 -07:00
|
|
|
hintStyle: Theme.of(context).textTheme.titleSmall?.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.5),
|
2023-03-28 08:34:06 -07:00
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
fontSize: 14,
|
2023-02-11 13:23:32 -07:00
|
|
|
),
|
2022-07-13 05:23:48 -07:00
|
|
|
enabledBorder: const UnderlineInputBorder(
|
2022-02-27 11:45:12 -07:00
|
|
|
borderSide: BorderSide(color: Colors.transparent),
|
|
|
|
),
|
2022-07-13 05:23:48 -07:00
|
|
|
focusedBorder: const UnderlineInputBorder(
|
2022-02-27 11:45:12 -07:00
|
|
|
borderSide: BorderSide(color: Colors.transparent),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
|
|
|
}
|