From 62122e5c79eba103abcf48ce75fb560043ab64ee Mon Sep 17 00:00:00 2001 From: krille-chan Date: Sun, 13 Aug 2023 11:15:13 +0200 Subject: [PATCH] fix: Do not allow empty search server --- assets/l10n/intl_en.arb | 1 + lib/pages/chat_list/chat_list.dart | 9 +++++++++ lib/pages/chat_list/chat_list_header.dart | 17 ++++++++++++----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index a84ec657..35339c47 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -1044,6 +1044,7 @@ "anyoneCanKnock": "Anyone can knock", "noOneCanJoin": "No one can join", "tryAgain": "Try again", + "invalidServerName": "Invalid server name", "invited": "Invited", "@invited": { "type": "text", diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index 234b43b7..88d6c512 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -181,6 +181,9 @@ class ChatListController extends State initialText: searchServer, keyboardType: TextInputType.url, autocorrect: false, + validator: (server) => server?.contains('.') == true + ? null + : L10n.of(context)!.invalidServerName, ) ], ); @@ -244,6 +247,12 @@ class ChatListController extends State _coolDown = Timer(const Duration(milliseconds: 500), _search); } + void startSearch() { + setState(() { + isSearchMode = true; + }); + } + void cancelSearch({bool unfocus = true}) { setState(() { searchController.clear(); diff --git a/lib/pages/chat_list/chat_list_header.dart b/lib/pages/chat_list/chat_list_header.dart index 0d49ea8a..8d58aed4 100644 --- a/lib/pages/chat_list/chat_list_header.dart +++ b/lib/pages/chat_list/chat_list_header.dart @@ -62,9 +62,12 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget { onPressed: controller.cancelSearch, color: Theme.of(context).colorScheme.onBackground, ) - : Icon( - Icons.search_outlined, - color: Theme.of(context).colorScheme.onBackground, + : IconButton( + onPressed: controller.startSearch, + icon: Icon( + Icons.search_outlined, + color: Theme.of(context).colorScheme.onBackground, + ), ), suffixIcon: controller.isSearchMode ? controller.isSearching @@ -80,12 +83,16 @@ class ChatListHeader extends StatelessWidget implements PreferredSizeWidget { ), ), ) - : TextButton( + : TextButton.icon( onPressed: controller.setServer, style: TextButton.styleFrom( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(99), + ), textStyle: const TextStyle(fontSize: 12), ), - child: Text( + icon: const Icon(Icons.edit_outlined, size: 16), + label: Text( controller.searchServer ?? Matrix.of(context) .client