flutter 控制器.animateTo position.maxScrollExtent在我的列表视图中不起作用

dm7nw8vv  于 2022-12-05  发布在  Flutter
关注(0)|答案(1)|浏览(171)

控制器.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,但不起作用。列表视图不向其下限移动

lp0sw83n

lp0sw83n1#

设定

ListView(
  shrinkWrap: true,
  otherParams: ...
  
)

相关问题