2021-01-08 17:38:48 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
|
|
|
|
import '../hooks/stores.dart';
|
|
|
|
import '../util/goto.dart';
|
|
|
|
import '../widgets/bottom_modal.dart';
|
|
|
|
import 'search_results.dart';
|
|
|
|
|
|
|
|
class SearchTab extends HookWidget {
|
|
|
|
const SearchTab();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final searchInputController = useTextEditingController();
|
|
|
|
|
|
|
|
final accStore = useAccountsStore();
|
2021-01-10 01:51:26 +01:00
|
|
|
final instanceHost = useState(accStore.instances.first);
|
2021-01-08 17:38:48 +01:00
|
|
|
useValueListenable(searchInputController);
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
),
|
2021-01-08 18:25:40 +01:00
|
|
|
body: GestureDetector(
|
|
|
|
onTapDown: (_) => primaryFocus.unfocus(),
|
|
|
|
child: ListView(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
|
|
children: [
|
|
|
|
TextField(
|
|
|
|
controller: searchInputController,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
fillColor: Colors.grey,
|
|
|
|
isDense: true,
|
|
|
|
contentPadding: const EdgeInsets.symmetric(vertical: 10),
|
|
|
|
hintText: 'search',
|
|
|
|
border: OutlineInputBorder(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
2021-01-08 17:38:48 +01:00
|
|
|
),
|
|
|
|
),
|
2021-01-08 18:25:40 +01:00
|
|
|
const SizedBox(height: 5),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Text('instance:',
|
|
|
|
style: Theme.of(context).textTheme.subtitle1),
|
2021-01-08 17:38:48 +01:00
|
|
|
),
|
2021-01-08 18:25:40 +01:00
|
|
|
Expanded(
|
|
|
|
child: SelectInstanceButton(
|
2021-01-10 01:51:26 +01:00
|
|
|
instanceHost: instanceHost.value,
|
|
|
|
onChange: (s) => instanceHost.value = s,
|
2021-01-08 18:25:40 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
if (searchInputController.text.isNotEmpty)
|
|
|
|
ElevatedButton(
|
2021-01-09 19:24:07 +01:00
|
|
|
onPressed: () => goTo(
|
|
|
|
context,
|
|
|
|
(c) => SearchResultsPage(
|
2021-01-10 01:51:26 +01:00
|
|
|
instanceHost: instanceHost.value,
|
2021-01-09 19:24:07 +01:00
|
|
|
query: searchInputController.text,
|
|
|
|
)),
|
2021-01-08 18:25:40 +01:00
|
|
|
child: const Text('search'),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2021-01-08 17:38:48 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SelectInstanceButton extends HookWidget {
|
2021-01-09 20:09:50 +01:00
|
|
|
final ValueChanged<String> onChange;
|
2021-01-10 01:51:26 +01:00
|
|
|
final String instanceHost;
|
2021-01-09 19:54:55 +01:00
|
|
|
const SelectInstanceButton(
|
2021-01-10 14:47:53 +01:00
|
|
|
{@required this.onChange, @required this.instanceHost})
|
|
|
|
: assert(instanceHost != null);
|
2021-01-08 17:38:48 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
final accStore = useAccountsStore();
|
|
|
|
return OutlinedButton(
|
|
|
|
onPressed: () async {
|
|
|
|
final val = await showModalBottomSheet<String>(
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
isScrollControlled: true,
|
|
|
|
context: context,
|
|
|
|
builder: (context) => BottomModal(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
for (final inst in accStore.instances)
|
|
|
|
ListTile(
|
2021-01-10 01:51:26 +01:00
|
|
|
leading: inst == instanceHost
|
2021-01-08 17:38:48 +01:00
|
|
|
? Icon(
|
|
|
|
Icons.radio_button_on,
|
|
|
|
color: theme.accentColor,
|
|
|
|
)
|
|
|
|
: const Icon(Icons.radio_button_off),
|
|
|
|
title: Text(inst),
|
|
|
|
onTap: () => Navigator.of(context).pop(inst),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
));
|
|
|
|
if (val != null) {
|
2021-01-09 19:55:52 +01:00
|
|
|
onChange?.call(val);
|
2021-01-08 17:38:48 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
style: OutlinedButton.styleFrom(
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(10))),
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 15),
|
|
|
|
primary: theme.textTheme.bodyText1.color,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
2021-01-10 01:51:26 +01:00
|
|
|
Text(instanceHost),
|
2021-01-08 17:38:48 +01:00
|
|
|
const Icon(Icons.arrow_drop_down),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|