我已经重构了此 TextFromField 以在“设置页面”中重新使用,当我调用它时,我必须传递用户当前所在的TextFormField的FocusNode和下面的TextFormField。
问题是,当我在具有 maxLine:1 的TextFormField中按键盘上的 TextInputAction.next 时,下一个具有 > maxLine:3 ,它并没有真正集中在下一个上,光标确实移到了下一个,但是由于所有这些TextFormFields都在ListView中,如果当前不可见下一个TextFormField,则它不会移动到它。
因此,除非滚动,否则我所拥有的光标将移至看不见的下一个TextFormField。有关如何解决此问题的任何想法?
class SetUpTextFromField extends StatelessWidget {
//
SetUpTextFormField({
@required this.onChanged,
@required this.context,
this.maxLines,
this.currentFocus,
this.nextFocus,
this.textInputAction,
});
//
final Function onChanged;
final BuildContext context;
final int maxLines;
final FocusNode currentFocus, nextFocus;
final TextInputAction textInputAction;
//
@override
Widget build(BuildContext context) {
return TextFormField(
focusNode: currentFocus,
onFieldSubmitted: (term) {
currentFocus.unfocus();
FocusScope.of(context).requestFocus(nextFocus);
},
textInputAction: textInputAction ?? TextInputAction.done,
decoration: InputDecoration(
focusedBorder: new UnderlineInputBorder(
borderSide: new BorderSide(color: kAppLightPurple),
),
),
maxLines: maxLines ?? 1,
onChanged: onChanged,
style: TextStyle(...),
);
}
}
这是我的用法:
FocusNode biographyFocus = FocusNode();
FocusNode ageFocus= FocusNode();
SetUpOrEditTextField(
context: context,
currentFocus: biographyFocus,
nextFocus: ageFocus,
textInputAction: TextInputAction.next,
maxLines: 3,
onChanged: (value) {...},
),