控制器.animateTo控制器.position.maxScrollExtent在我的列表视图中不工作
我代码:
class ForgotPasswordScreen extends StatefulWidget {
const ForgotPasswordScreen();
@override
State<StatefulWidget> createState() => ForgotPasswordScreenState();
}
class ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
late FocusNode phoneFocusNode;
final ScrollController controller = ScrollController();
@override
void initState() {
phoneFocusNode = FocusNode();
phoneFocusNode.addListener(() {
if (phoneFocusNode.hasFocus == true) {
print('true');
print(phoneFocusNode.hasFocus);
controller.animateTo(
controller.position.maxScrollExtent,
curve: Curves.easeOut,
duration: const Duration(milliseconds: 500),
);
} else {
print('false');
print(phoneFocusNode.hasFocus);
}
});
super.initState();
}
@override
void dispose() {
phoneFocusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
controller: controller,
children: [
InputText(
controller: _phoneNumberController,
prefixText: '+68 ',
focusNode: phoneFocusNode,
),
const SizedBox(height: 30),
Button(
onPressed: () {},
child: Text(
'Next',
),
),
],
),
);
}
}
我希望输入文本为focusnode。hasFocus == true。可以滚动到列表视图的底部。hasFocus值为true,但不起作用。列表视图不向其下限移动
1条答案
按热度按时间lp0sw83n1#
设定