Fix autofocus on android + auto select text fields in settings to make them easier to change.
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
1e2c69eb4c
commit
e55a7e940e
|
@ -102,7 +102,7 @@ class _AddEditProfileViewState extends State<AddEditProfileView> {
|
||||||
),
|
),
|
||||||
CwtchTextField(
|
CwtchTextField(
|
||||||
controller: ctrlrNick,
|
controller: ctrlrNick,
|
||||||
autofocus: true,
|
autofocus: false,
|
||||||
labelText: AppLocalizations.of(context)!.yourDisplayName,
|
labelText: AppLocalizations.of(context)!.yourDisplayName,
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value.isEmpty) {
|
if (value.isEmpty) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:cwtch/cwtch_icons_icons.dart';
|
import 'package:cwtch/cwtch_icons_icons.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
@ -129,7 +130,7 @@ class _MessageViewState extends State<MessageView> {
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
key: Key('txtCompose'),
|
key: Key('txtCompose'),
|
||||||
controller: ctrlrCompose,
|
controller: ctrlrCompose,
|
||||||
autofocus: true,
|
autofocus: !Platform.isAndroid,
|
||||||
focusNode: focusNode,
|
focusNode: focusNode,
|
||||||
textInputAction: TextInputAction.send,
|
textInputAction: TextInputAction.send,
|
||||||
onFieldSubmitted: _sendMessage,
|
onFieldSubmitted: _sendMessage,
|
||||||
|
@ -140,6 +141,9 @@ class _MessageViewState extends State<MessageView> {
|
||||||
prefixIcon: IconButton(
|
prefixIcon: IconButton(
|
||||||
icon: Icon(CwtchIcons.send_invite, size: 24, color: Provider.of<Settings>(context).theme.mainTextColor()),
|
icon: Icon(CwtchIcons.send_invite, size: 24, color: Provider.of<Settings>(context).theme.mainTextColor()),
|
||||||
tooltip: AppLocalizations.of(context)!.sendInvite,
|
tooltip: AppLocalizations.of(context)!.sendInvite,
|
||||||
|
enableFeedback: true,
|
||||||
|
splashColor: Provider.of<Settings>(context).theme.defaultButtonActiveColor(),
|
||||||
|
hoverColor: Provider.of<Settings>(context).theme.defaultButtonActiveColor(),
|
||||||
onPressed: () => _modalSendInvitation(context)),
|
onPressed: () => _modalSendInvitation(context)),
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
icon: Icon(CwtchIcons.send_24px, size: 24, color: Provider.of<Settings>(context).theme.mainTextColor()),
|
icon: Icon(CwtchIcons.send_24px, size: 24, color: Provider.of<Settings>(context).theme.mainTextColor()),
|
||||||
|
|
|
@ -17,6 +17,18 @@ class CwtchButtonTextField extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CwtchButtonTextFieldState extends State<CwtchButtonTextField> {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Consumer<Settings>(builder: (context, theme, child) {
|
return Consumer<Settings>(builder: (context, theme, child) {
|
||||||
|
@ -24,6 +36,7 @@ class _CwtchButtonTextFieldState extends State<CwtchButtonTextField> {
|
||||||
controller: widget.controller,
|
controller: widget.controller,
|
||||||
readOnly: widget.readonly,
|
readOnly: widget.readonly,
|
||||||
showCursor: !widget.readonly,
|
showCursor: !widget.readonly,
|
||||||
|
focusNode: _focusNode,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
onPressed: widget.onPressed,
|
onPressed: widget.onPressed,
|
||||||
|
|
|
@ -7,7 +7,7 @@ doNothing(String x) {}
|
||||||
// Provides a styled Text Field for use in Form Widgets.
|
// Provides a styled Text Field for use in Form Widgets.
|
||||||
// Callers must provide a text controller, label helper text and a validator.
|
// Callers must provide a text controller, label helper text and a validator.
|
||||||
class CwtchTextField extends StatefulWidget {
|
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 TextEditingController controller;
|
||||||
final String labelText;
|
final String labelText;
|
||||||
final FormFieldValidator? validator;
|
final FormFieldValidator? validator;
|
||||||
|
@ -19,6 +19,18 @@ class CwtchTextField extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CwtchTextFieldState extends State<CwtchTextField> {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Consumer<Settings>(builder: (context, theme, child) {
|
return Consumer<Settings>(builder: (context, theme, child) {
|
||||||
|
@ -27,6 +39,7 @@ class _CwtchTextFieldState extends State<CwtchTextField> {
|
||||||
validator: widget.validator,
|
validator: widget.validator,
|
||||||
onChanged: widget.onChanged,
|
onChanged: widget.onChanged,
|
||||||
autofocus: widget.autofocus,
|
autofocus: widget.autofocus,
|
||||||
|
focusNode: _focusNode,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: widget.labelText,
|
labelText: widget.labelText,
|
||||||
labelStyle: TextStyle(color: theme.current().mainTextColor(), backgroundColor: theme.current().textfieldBackgroundColor()),
|
labelStyle: TextStyle(color: theme.current().mainTextColor(), backgroundColor: theme.current().textfieldBackgroundColor()),
|
||||||
|
|
Loading…
Reference in New Issue