我创建了一个可重用的textformfield。我可以在任何档案中调用。不过,我确实有个问题。如果我点击“电子邮件地址”的TextFormField,“密码”的TextFormField也会激活。下面是我在Stateful Widget中调用的基于类的函数。
登录_页面.dart
// whenever I tap to input a email on this textformfield, it actives the textformfield
// of the userPassword as well.
FormFields.textFormFieldWidget(
controller: _userEmail,
hintText: "Email Address",
hintStyle: CustomTextStyle.reusableTextStyle(
customColor: const Color(0xFF999EA1),
customFontSize: 14,
customFontWeight: FontWeight.w600),
borderColor: const Color(0xFFCDD1E0),
colorFilled: _color,
textFieldFocus: _textFieldFocus,
),
const SizedBox(
height: 12,
),
FormFields.textFormFieldWidget(
controller: _userPassword,
isPassword: true,
hintText: "Password",
hintStyle: CustomTextStyle.reusableTextStyle(
customColor: const Color(0xFF999EA1),
customFontSize: 14,
customFontWeight: FontWeight.w600),
borderColor: const Color(0xFFCDD1E0),
colorFilled: _color,
suffixIcon: Icons.remove_red_eye,
textFieldFocus: _textFieldFocus,
),
这是我的可重用textformfield的声明和实现。reusable_widget.dart
import 'package:flutter/material.dart';
class FormFields {
static textFormFieldWidget({
TextEditingController? controller,
String? hintText,
String? helpText,
IconData? prefixIcon,
IconData? suffixIcon,
bool? isPassword,
bool? enabled,
bool? readOnly,
Color? borderColor,
Color? borderSide,
Color? colorFilled,
FocusNode? textFieldFocus,
TextStyle? hintStyle,
}) {
return TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
controller: controller,
readOnly: readOnly == null ? false : true,
obscureText: isPassword == null ? false : true,
decoration: InputDecoration(
fillColor: colorFilled,
filled: true,
focusedBorder: OutlineInputBorder(
borderRadius: const BorderRadius.all(
Radius.circular(10.0)),
borderSide: BorderSide(
color: borderSide ?? const Color(0xFF6949FF),
width: 1.15
),
),
enabledBorder: OutlineInputBorder(
borderRadius: const BorderRadius.all(
Radius.circular(10.0)),
borderSide: BorderSide(
color: borderSide ?? const Color(0xFFCDD1E0),
width: 1.15,
),
),
// dont forget this line
hintText: hintText ?? '',
hintStyle: hintStyle ?? TextStyle(),
helperText: helpText ?? '',
prefixIcon: null == prefixIcon ? null : Icon(prefixIcon),
suffix: null == suffixIcon ? null : Icon(suffixIcon),
enabled: null == enabled ? true : false,
),
focusNode: textFieldFocus,
textAlignVertical: TextAlignVertical.center,
);
}
}
我只想使textformfield激活,如果我点击它或触摸它的区域,而不是激活所有textformfield。
1条答案
按热度按时间txu3uszq1#
您的两个
textfields
具有相同的FocusNode
、_textFieldFocus
。给予他们两个不同的
FocusNodes
。