dart 键盘弹出时,Flutter不显示小部件

ve7v8dk2  于 2023-04-27  发布在  Flutter
关注(0)|答案(1)|浏览(153)

我想在键盘弹出时显示小部件,但收到错误消息

======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
RenderFlex children have non-zero flex but incoming height constraints are unbounded.

When a column is in a parent that does not provide a finite height constraint, for example if it is in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining space in the vertical direction.
These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child cannot simultaneously expand to fit its parent.

Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible children (using Flexible rather than Expanded). This will allow the flexible children to size themselves to less than the infinite remaining space they would otherwise be forced to take, and then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum constraints provided by the parent.

我试着用SingleChildScrollView .我从youtube上得到它,但它仍然不工作.

这是密码

return Scaffold(
      backgroundColor: backgroundColor1,
      body: SafeArea(
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min,
              children: [
                header(),
                fullNameInput(),
                userNameInput(),
                emailInput(),
                passwordInput(),
                button(),
                const Spacer(),
                footer()
              ],
            ),
          ),
        ),
    );

怎么修?

ni65a41a

ni65a41a1#

像这样使用大小框

Scaffold(
  body: SafeArea(
    child: SingleChildScrollView(
      child: SizedBox(
        height: MediaQuery.of(context).size.height,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: [
            header(),
            fullNameInput(),
            userNameInput(),
            emailInput(),
            passwordInput(),
            button(),
            const Spacer(),
            footer()
          ],
        ),
      ),
    ),
  ),
);

相关问题