Fix autofocus on android + auto select text fields in settings to make them easier to change.
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2021-06-15 12:43:58 -07:00
parent 1e2c69eb4c
commit e55a7e940e
4 changed files with 33 additions and 3 deletions

View File

@ -102,7 +102,7 @@ class _AddEditProfileViewState extends State<AddEditProfileView> {
),
CwtchTextField(
controller: ctrlrNick,
autofocus: true,
autofocus: false,
labelText: AppLocalizations.of(context)!.yourDisplayName,
validator: (value) {
if (value.isEmpty) {

View File

@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:io';
import 'package:cwtch/cwtch_icons_icons.dart';
import 'package:flutter/cupertino.dart';
@ -129,7 +130,7 @@ class _MessageViewState extends State<MessageView> {
child: TextFormField(
key: Key('txtCompose'),
controller: ctrlrCompose,
autofocus: true,
autofocus: !Platform.isAndroid,
focusNode: focusNode,
textInputAction: TextInputAction.send,
onFieldSubmitted: _sendMessage,
@ -140,6 +141,9 @@ class _MessageViewState extends State<MessageView> {
prefixIcon: IconButton(
icon: Icon(CwtchIcons.send_invite, size: 24, color: Provider.of<Settings>(context).theme.mainTextColor()),
tooltip: AppLocalizations.of(context)!.sendInvite,
enableFeedback: true,
splashColor: Provider.of<Settings>(context).theme.defaultButtonActiveColor(),
hoverColor: Provider.of<Settings>(context).theme.defaultButtonActiveColor(),
onPressed: () => _modalSendInvitation(context)),
suffixIcon: IconButton(
icon: Icon(CwtchIcons.send_24px, size: 24, color: Provider.of<Settings>(context).theme.mainTextColor()),

View File

@ -17,6 +17,18 @@ class CwtchButtonTextField extends StatefulWidget {
}
class _CwtchButtonTextFieldState extends State<CwtchButtonTextField> {
late final FocusNode _focusNode;
@override
void initState() {
_focusNode = FocusNode();
_focusNode.addListener(() {
// Select all...
if (_focusNode.hasFocus) widget.controller.selection = TextSelection(baseOffset: 0, extentOffset: widget.controller.text.length);
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Consumer<Settings>(builder: (context, theme, child) {
@ -24,6 +36,7 @@ class _CwtchButtonTextFieldState extends State<CwtchButtonTextField> {
controller: widget.controller,
readOnly: widget.readonly,
showCursor: !widget.readonly,
focusNode: _focusNode,
decoration: InputDecoration(
suffixIcon: IconButton(
onPressed: widget.onPressed,

View File

@ -7,7 +7,7 @@ doNothing(String x) {}
// Provides a styled Text Field for use in Form Widgets.
// Callers must provide a text controller, label helper text and a validator.
class CwtchTextField extends StatefulWidget {
CwtchTextField({required this.controller, required this.labelText, this.validator = null, this.autofocus = false, this.onChanged = doNothing});
CwtchTextField({required this.controller, required this.labelText, this.validator, this.autofocus = false, this.onChanged = doNothing});
final TextEditingController controller;
final String labelText;
final FormFieldValidator? validator;
@ -19,6 +19,18 @@ class CwtchTextField extends StatefulWidget {
}
class _CwtchTextFieldState extends State<CwtchTextField> {
late final FocusNode _focusNode;
@override
void initState() {
_focusNode = FocusNode();
_focusNode.addListener(() {
// Select all...
if (_focusNode.hasFocus) widget.controller.selection = TextSelection(baseOffset: 0, extentOffset: widget.controller.text.length);
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Consumer<Settings>(builder: (context, theme, child) {
@ -27,6 +39,7 @@ class _CwtchTextFieldState extends State<CwtchTextField> {
validator: widget.validator,
onChanged: widget.onChanged,
autofocus: widget.autofocus,
focusNode: _focusNode,
decoration: InputDecoration(
labelText: widget.labelText,
labelStyle: TextStyle(color: theme.current().mainTextColor(), backgroundColor: theme.current().textfieldBackgroundColor()),