diff --git a/lib/components/default_app_bar_search_field.dart b/lib/components/default_app_bar_search_field.dart index cf715925..4df93706 100644 --- a/lib/components/default_app_bar_search_field.dart +++ b/lib/components/default_app_bar_search_field.dart @@ -1,16 +1,21 @@ import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; class DefaultAppBarSearchField extends StatefulWidget { final TextEditingController searchController; final void Function(String) onChanged; final Widget suffix; + final bool autofocus; + final String prefixText; + final String hintText; const DefaultAppBarSearchField({ Key key, this.searchController, this.onChanged, this.suffix, + this.autofocus = false, + this.prefixText, + this.hintText, }) : super(key: key); @override @@ -59,11 +64,13 @@ class _DefaultAppBarSearchFieldState extends State { color: Theme.of(context).secondaryHeaderColor, borderRadius: BorderRadius.circular(32), child: TextField( + autofocus: widget.autofocus, autocorrect: false, controller: _searchController, onChanged: widget.onChanged, focusNode: _focusNode, decoration: InputDecoration( + prefixText: widget.prefixText, contentPadding: EdgeInsets.only( top: 8, bottom: 8, @@ -72,7 +79,7 @@ class _DefaultAppBarSearchFieldState extends State { border: OutlineInputBorder( borderRadius: BorderRadius.circular(32), ), - hintText: L10n.of(context).searchForAChat, + hintText: widget.hintText, suffixIcon: _focusNode.hasFocus || (widget.suffix == null && (_searchController.text?.isNotEmpty ?? false)) diff --git a/lib/views/chat_list.dart b/lib/views/chat_list.dart index 9a5ed918..c827e4a3 100644 --- a/lib/views/chat_list.dart +++ b/lib/views/chat_list.dart @@ -272,6 +272,7 @@ class _ChatListState extends State { ? Text(_selectedRoomIds.length.toString()) : DefaultAppBarSearchField( searchController: searchController, + hintText: L10n.of(context).searchForAChat, onChanged: (_) => setState(() => null), ), ), diff --git a/lib/views/discover_view.dart b/lib/views/discover_view.dart index bd0ec210..1f5d9313 100644 --- a/lib/views/discover_view.dart +++ b/lib/views/discover_view.dart @@ -146,6 +146,7 @@ class _DiscoverPageState extends State { elevation: _scrolledToTop ? 0 : null, title: DefaultAppBarSearchField( onChanged: (text) => _search(context, text), + hintText: L10n.of(context).searchForAChat, suffix: IconButton( icon: Icon(Icons.edit_outlined), onPressed: () => _setServer(context), diff --git a/lib/views/invitation_selection.dart b/lib/views/invitation_selection.dart index ff4c3c5b..a920c9b3 100644 --- a/lib/views/invitation_selection.dart +++ b/lib/views/invitation_selection.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:fluffychat/components/default_app_bar_search_field.dart'; import 'package:flushbar/flushbar_helper.dart'; import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/matrix_api.dart'; @@ -120,35 +121,11 @@ class _InvitationSelectionState extends State { firstScaffold: ChatList(activeChat: widget.room.id), secondScaffold: Scaffold( appBar: AppBar( - title: Text(L10n.of(context).inviteContact), - bottom: PreferredSize( - preferredSize: Size.fromHeight(92), - child: Padding( - padding: const EdgeInsets.all(16.0), - child: TextField( - controller: controller, - autofocus: true, - autocorrect: false, - textInputAction: TextInputAction.search, - onChanged: (String text) => - searchUserWithCoolDown(context, text), - onSubmitted: (String text) => searchUser(context, text), - decoration: InputDecoration( - border: OutlineInputBorder(), - prefixText: '@', - hintText: L10n.of(context).username, - labelText: L10n.of(context).inviteContactToGroup(groupName), - suffixIcon: loading - ? Container( - padding: const EdgeInsets.all(8.0), - width: 12, - height: 12, - child: CircularProgressIndicator(), - ) - : Icon(Icons.search_outlined), - ), - ), - ), + titleSpacing: 0, + title: DefaultAppBarSearchField( + autofocus: true, + hintText: L10n.of(context).inviteContactToGroup(groupName), + onChanged: (String text) => searchUserWithCoolDown(context, text), ), ), body: foundProfiles.isNotEmpty