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> {
TextEditingController controller = TextEditingController();
final TextEditingController controller = TextEditingController();
final FocusNode textFieldFocus = FocusNode();
final formKey = GlobalKey<FormState>();
bool loading = false;
bool hideFab = false;
static const Set<String> supportedSigils = {'@', '!', '#'};
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 {
controller.text = controller.text.trim();
if (!formKey.currentState.validate()) return;

View File

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