1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-09 13:26:47 +01:00
immich/mobile/lib/modules/search/views/search_page.dart

57 lines
1.8 KiB
Dart
Raw Normal View History

2022-03-02 23:44:24 +01:00
import 'package:auto_route/auto_route.dart';
2022-02-27 19:45:12 +01: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';
import 'package:immich_mobile/modules/search/ui/search_bar.dart';
import 'package:immich_mobile/modules/search/ui/search_suggestion_list.dart';
2022-03-02 23:44:24 +01:00
import 'package:immich_mobile/routing/router.dart';
2022-02-27 19:45:12 +01:00
// ignore: must_be_immutable
class SearchPage extends HookConsumerWidget {
SearchPage({Key? key}) : super(key: key);
late FocusNode searchFocusNode;
@override
Widget build(BuildContext context, WidgetRef ref) {
final isSearchEnabled = ref.watch(searchPageStateProvider).isSearchEnabled;
useEffect(() {
searchFocusNode = FocusNode();
return () => searchFocusNode.dispose();
2022-02-27 19:45:12 +01:00
}, []);
2022-03-02 23:44:24 +01:00
_onSearchSubmitted(String searchTerm) async {
searchFocusNode.unfocus();
ref.watch(searchPageStateProvider.notifier).disableSearch();
AutoRouter.of(context).push(SearchResultRoute(searchTerm: searchTerm));
}
2022-02-27 19:45:12 +01:00
return Scaffold(
2022-03-02 23:44:24 +01:00
appBar: SearchBar(
searchFocusNode: searchFocusNode,
onSubmitted: _onSearchSubmitted,
),
2022-02-27 19:45:12 +01:00
body: GestureDetector(
onTap: () {
searchFocusNode.unfocus();
ref.watch(searchPageStateProvider.notifier).disableSearch();
},
child: Stack(
children: [
const Center(
child: Text("Start typing to search for your photos"),
),
2022-02-27 19:45:12 +01:00
ListView(
children: const [],
2022-02-27 19:45:12 +01:00
),
2022-03-02 23:44:24 +01:00
isSearchEnabled ? SearchSuggestionList(onSubmitted: _onSearchSubmitted) : Container(),
2022-02-27 19:45:12 +01:00
],
),
),
);
}
}