Improve tap to dismiss keyboard on home/search

This commit is contained in:
tommyxchow 2022-01-19 15:37:20 -05:00
parent 24cdfd699a
commit c623daceae
2 changed files with 115 additions and 115 deletions

View file

@ -32,67 +32,70 @@ class Home extends StatelessWidget {
Widget build(BuildContext context) {
final authStore = context.read<AuthStore>();
return Scaffold(
appBar: AppBar(
centerTitle: false,
title: Observer(
builder: (_) {
final titles = [
if (authStore.isLoggedIn) 'Followed Streams',
'Top',
'Search',
];
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: Scaffold(
appBar: AppBar(
centerTitle: false,
title: Observer(
builder: (_) {
final titles = [
if (authStore.isLoggedIn) 'Followed Streams',
'Top',
'Search',
];
return Text(titles[homeStore.selectedIndex]);
},
return Text(titles[homeStore.selectedIndex]);
},
),
actions: [
IconButton(
tooltip: 'Settings',
icon: const Icon(Icons.settings),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Settings(settingsStore: context.read<SettingsStore>()),
),
),
)
],
),
actions: [
IconButton(
tooltip: 'Settings',
icon: const Icon(Icons.settings),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Settings(settingsStore: context.read<SettingsStore>()),
),
body: SafeArea(
child: Observer(
builder: (_) => IndexedStack(
index: homeStore.selectedIndex,
children: [
if (authStore.isLoggedIn) StreamsList(store: followedStreamsStore!),
TopSection(
topSectionStore: topSectionStore,
categoriesSectionStore: categoriesSectionStore,
),
Search(searchStore: searchStore),
],
),
)
],
),
body: SafeArea(
child: Observer(
builder: (_) => IndexedStack(
index: homeStore.selectedIndex,
children: [
if (authStore.isLoggedIn) StreamsList(store: followedStreamsStore!),
TopSection(
topSectionStore: topSectionStore,
categoriesSectionStore: categoriesSectionStore,
),
Search(searchStore: searchStore),
],
),
),
),
bottomNavigationBar: Observer(
builder: (_) => BottomNavigationBar(
items: [
if (authStore.isLoggedIn)
bottomNavigationBar: Observer(
builder: (_) => BottomNavigationBar(
items: [
if (authStore.isLoggedIn)
const BottomNavigationBarItem(
icon: Icon(Icons.favorite),
label: 'Followed',
),
const BottomNavigationBarItem(
icon: Icon(Icons.favorite),
label: 'Followed',
icon: Icon(Icons.arrow_upward),
label: 'Top',
),
const BottomNavigationBarItem(
icon: Icon(Icons.arrow_upward),
label: 'Top',
),
const BottomNavigationBarItem(
icon: Icon(Icons.search),
label: 'Search',
),
],
currentIndex: homeStore.selectedIndex,
onTap: homeStore.handleTap,
const BottomNavigationBarItem(
icon: Icon(Icons.search),
label: 'Search',
),
],
currentIndex: homeStore.selectedIndex,
onTap: homeStore.handleTap,
),
),
),
);

View file

@ -52,73 +52,70 @@ class _SearchState extends State<Search> {
),
),
Expanded(
child: GestureDetector(
onTap: FocusManager.instance.primaryFocus?.unfocus,
child: Observer(
builder: (context) {
if (textEditingController.text.isEmpty || searchStore.channelFuture == null || searchStore.categoryFuture == null) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (searchStore.searchHistory.isNotEmpty)
const Padding(
padding: EdgeInsets.all(15.0),
child: Text(
'HISTORY',
style: TextStyle(fontWeight: FontWeight.bold),
),
child: Observer(
builder: (context) {
if (textEditingController.text.isEmpty || searchStore.channelFuture == null || searchStore.categoryFuture == null) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (searchStore.searchHistory.isNotEmpty)
const Padding(
padding: EdgeInsets.all(15.0),
child: Text(
'HISTORY',
style: TextStyle(fontWeight: FontWeight.bold),
),
Expanded(
child: ListView(
children: searchStore.searchHistory
.mapIndexed(
(index, searchTerm) => ListTile(
leading: const Icon(Icons.history),
title: Text(searchTerm),
trailing: IconButton(
tooltip: 'Remove',
icon: const Icon(Icons.cancel),
onPressed: () => setState(() {
searchStore.searchHistory.removeAt(index);
}),
),
onTap: () {
setState(() {
textEditingController.text = searchTerm;
searchStore.handleQuery(searchTerm);
});
},
),
Expanded(
child: ListView(
children: searchStore.searchHistory
.mapIndexed(
(index, searchTerm) => ListTile(
leading: const Icon(Icons.history),
title: Text(searchTerm),
trailing: IconButton(
tooltip: 'Remove',
icon: const Icon(Icons.cancel),
onPressed: () => setState(() {
searchStore.searchHistory.removeAt(index);
}),
),
)
.toList(),
),
),
],
);
}
return CustomScrollView(
slivers: [
const SliverToBoxAdapter(
child: SectionHeader(
'Channels',
padding: headerPadding,
onTap: () {
setState(() {
textEditingController.text = searchTerm;
searchStore.handleQuery(searchTerm);
});
},
),
)
.toList(),
),
),
SearchResultsChannels(
searchStore: searchStore,
query: textEditingController.text,
),
const SliverToBoxAdapter(
child: SectionHeader(
'Categories',
padding: headerPadding,
),
),
SearchResultsCategories(searchStore: searchStore),
],
);
},
),
}
return CustomScrollView(
slivers: [
const SliverToBoxAdapter(
child: SectionHeader(
'Channels',
padding: headerPadding,
),
),
SearchResultsChannels(
searchStore: searchStore,
query: textEditingController.text,
),
const SliverToBoxAdapter(
child: SectionHeader(
'Categories',
padding: headerPadding,
),
),
SearchResultsCategories(searchStore: searchStore),
],
);
},
),
),
],