From 9fa198c3bb91437d8320b7741bdccd89796f1887 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Sun, 11 Apr 2021 16:36:29 +0200 Subject: [PATCH] Add keyboard dismisser --- lib/main.dart | 21 ++++++----- lib/pages/search_tab.dart | 73 +++++++++++++++++++-------------------- pubspec.lock | 7 ++++ pubspec.yaml | 1 + 4 files changed, 55 insertions(+), 47 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index ebbe6e6..e2261fa 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; +import 'package:keyboard_dismisser/keyboard_dismisser.dart'; import 'package:provider/provider.dart'; import 'hooks/stores.dart'; @@ -41,15 +42,17 @@ class MyApp extends HookWidget { Widget build(BuildContext context) { final configStore = useConfigStore(); - return MaterialApp( - title: 'lemmur', - supportedLocales: L10n.supportedLocales, - localizationsDelegates: L10n.localizationsDelegates, - themeMode: configStore.theme, - darkTheme: configStore.amoledDarkMode ? amoledTheme : darkTheme, - locale: configStore.locale, - theme: lightTheme, - home: const MyHomePage(), + return KeyboardDismisser( + child: MaterialApp( + title: 'lemmur', + supportedLocales: L10n.supportedLocales, + localizationsDelegates: L10n.localizationsDelegates, + themeMode: configStore.theme, + darkTheme: configStore.amoledDarkMode ? amoledTheme : darkTheme, + locale: configStore.locale, + theme: lightTheme, + home: const MyHomePage(), + ), ); } } diff --git a/lib/pages/search_tab.dart b/lib/pages/search_tab.dart index f749e2c..c975b90 100644 --- a/lib/pages/search_tab.dart +++ b/lib/pages/search_tab.dart @@ -33,45 +33,42 @@ class SearchTab extends HookWidget { return Scaffold( appBar: AppBar(), - body: GestureDetector( - onTapDown: (_) => primaryFocus?.unfocus(), - child: 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), + 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, ), - 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), - ) - ], - ), + ), + ], + ), + if (searchInputController.text.isNotEmpty) + ElevatedButton( + onPressed: () => goTo( + context, + (c) => SearchResultsPage( + instanceHost: instanceHost.value!, + query: searchInputController.text, + )), + child: Text(L10n.of(context)!.search), + ) + ], ), ); } diff --git a/pubspec.lock b/pubspec.lock index 207920b..00e9e7d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -392,6 +392,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.1.0" + keyboard_dismisser: + dependency: "direct main" + description: + name: keyboard_dismisser + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" latinize: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 361f91a..20d5e59 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,6 +47,7 @@ dependencies: intl: ^0.17.0 matrix4_transform: ^2.0.0 json_annotation: ^4.0.1 + keyboard_dismisser: ^2.0.0 flutter: sdk: flutter