import 'package:collection/collection.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import '../hooks/stores.dart'; import '../l10n/l10n.dart'; import '../util/goto.dart'; import '../widgets/radio_picker.dart'; import 'search_results.dart'; class SearchTab extends HookWidget { const SearchTab(); @override Widget build(BuildContext context) { final searchInputController = useListenable(useTextEditingController()); final accStore = useAccountsStore(); // null if there are no added instances final instanceHost = useState( accStore.instances.firstWhereOrNull((_) => true), ); if (instanceHost.value == null) { return Scaffold( appBar: AppBar(), body: const Center( child: Text('You do not have any instances added'), ), ); } return Scaffold( appBar: AppBar(), body: ListView( padding: const EdgeInsets.symmetric(horizontal: 20), children: [ TextField( controller: searchInputController, textAlign: TextAlign.center, decoration: InputDecoration(hintText: L10n.of(context)!.search), ), const SizedBox(height: 5), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Expanded( child: Text('instance:', style: Theme.of(context).textTheme.subtitle1), ), Expanded( child: RadioPicker( values: accStore.instances.toList(), groupValue: instanceHost.value!, onChanged: (value) => instanceHost.value = value, ), ), ], ), if (searchInputController.text.isNotEmpty) ElevatedButton( onPressed: () => goTo( context, (c) => SearchResultsPage( instanceHost: instanceHost.value!, query: searchInputController.text, )), child: Text(L10n.of(context)!.search), ) ], ), ); } }