fix: Hide FAB in new chat page if textfield has focus

This commit is contained in:
Krille Fear 2021-11-13 18:09:16 +01:00
parent fcc41a8d1d
commit eb429267b1
2 changed files with 23 additions and 2 deletions

View File

@ -18,14 +18,34 @@ class NewPrivateChat extends StatefulWidget {
} }
class NewPrivateChatController extends State<NewPrivateChat> { class NewPrivateChatController extends State<NewPrivateChat> {
TextEditingController controller = TextEditingController(); final TextEditingController controller = TextEditingController();
final FocusNode textFieldFocus = FocusNode();
final formKey = GlobalKey<FormState>(); final formKey = GlobalKey<FormState>();
bool loading = false; bool loading = false;
bool hideFab = false;
static const Set<String> supportedSigils = {'@', '!', '#'}; static const Set<String> supportedSigils = {'@', '!', '#'};
static const String prefix = 'https://matrix.to/#/'; static const String prefix = 'https://matrix.to/#/';
void setHideFab() {
if (textFieldFocus.hasFocus != hideFab) {
setState(() => hideFab = textFieldFocus.hasFocus);
}
}
@override
void initState() {
super.initState();
textFieldFocus.addListener(setHideFab);
}
@override
void dispose() {
textFieldFocus.removeListener(setHideFab);
super.dispose();
}
void submitAction([_]) async { void submitAction([_]) async {
controller.text = controller.text.trim(); controller.text = controller.text.trim();
if (!formKey.currentState.validate()) return; if (!formKey.currentState.validate()) return;

View File

@ -81,6 +81,7 @@ class NewPrivateChatView extends StatelessWidget {
controller: controller.controller, controller: controller.controller,
autocorrect: false, autocorrect: false,
textInputAction: TextInputAction.go, textInputAction: TextInputAction.go,
focusNode: controller.textFieldFocus,
onFieldSubmitted: controller.submitAction, onFieldSubmitted: controller.submitAction,
validator: controller.validateForm, validator: controller.validateForm,
decoration: InputDecoration( decoration: InputDecoration(
@ -105,7 +106,7 @@ class NewPrivateChatView extends StatelessWidget {
], ],
), ),
), ),
floatingActionButton: PlatformInfos.isMobile floatingActionButton: PlatformInfos.isMobile && !controller.hideFab
? FloatingActionButton.extended( ? FloatingActionButton.extended(
onPressed: controller.openScannerAction, onPressed: controller.openScannerAction,
label: Text(L10n.of(context).scanQrCode), label: Text(L10n.of(context).scanQrCode),