AnimatedContainer 调整高度时出现溢出警告

2024-01-10

Example https://gfycat.com/AdventurousOblongGoa

使用 CupertinoPicker,我希望它使用 AnimatedContainer 以动画方式进入文本输入下方的视图,但是当它变得可见时,我收到溢出警告。据我所知,您无法调整 CupertinoPicker 的大小,只能调整它的父级。

有更好的解决方案吗?

Column(
    children: <Widget>[
        buildTextField(
            field: 'limit',
            label: 'How Many Guests?',
            controller: TextEditingController(
                text: eventModel.event['limit']),
            onTap: () {
                showPicker.value = !showPicker.value;
            },
        ),
            AnimatedContainer(
            height: showPicker.value ? 150 : 0,
            duration: Duration(milliseconds: 150),
            child: showPicker.value
                ? CupertinoPicker(
                    backgroundColor: Colors.transparent,
                    itemExtent: 40,
                    children: List<Widget>.generate(
                        98,
                        (index) => Center(
                            child: Text(
                                '${index + 2}',
                                style: TextStyle(
                                    color: Colors.black,
                                    fontSize: 16),
                            ),
                            ),
                    ),
                    onSelectedItemChanged: (item) {
                        print((item + 2).toString());
                    },
                    )
                : null,
        ),
    ]
)

例外:

flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following message was thrown during layout:
flutter: A RenderFlex overflowed by 22 pixels on the bottom.
flutter:
flutter: The overflowing RenderFlex has an orientation of Axis.vertical.
flutter: The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
flutter: black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
flutter: Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
flutter: RenderFlex to fit within the available space instead of being sized to their natural size.
flutter: This is considered an error condition because it indicates that there is content that cannot be
flutter: seen. If the content is legitimately bigger than the available space, consider clipping it with a
flutter: ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
flutter: like a ListView.
flutter: The specific RenderFlex in question is:
flutter:   RenderFlex#73b9d relayoutBoundary=up16 OVERFLOWING
flutter:   creator: Column ← Stack ← CupertinoPicker ← ConstrainedBox ← Container ← AnimatedContainer ←
flutter:   Column ← Observer ← _FormScope ← WillPopScope ← Form ← Padding ← ⋯
flutter:   parentData: not positioned; offset=Offset(0.0, 0.0) (can use size)
flutter:   constraints: BoxConstraints(0.0<=w<=346.9, 0.0<=h<=18.2)
flutter:   size: Size(346.9, 18.2)
flutter:   direction: vertical
flutter:   mainAxisAlignment: start
flutter:   mainAxisSize: max
flutter:   crossAxisAlignment: center
flutter:   verticalDirection: down
flutter: ◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
flutter: Another exception was thrown: A RenderFlex overflowed by 22 pixels on the bottom.

您可以使用 SingleChildScrollView 包装其他小部件,如下所示:

AnimatedContainer( 
duration:Duration(milliseconds:500),
    child: SingleChildScrollView(child:contents),
),
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

AnimatedContainer 调整高度时出现溢出警告 的相关文章

  • flutter run 无法在 iOS 模拟器上运行,但 Xcode 可以构建

    在我的 Flutter 项目中 flutter run命令无法将项目构建到 iOS 模拟器 但在 Xcode 中 当我单击构建按钮时 Xcode 可以毫无问题地构建它 我正在使用 AgoraRTC 库 添加 Flutter Quill 后就
  • 颤动中的单选按钮对齐

    我是颤振的新手 我想对齐单选按钮 即 无论文本是什么 单选按钮都应该按列对齐 我在用Column然后小部件Row其中的小部件但得到以下结果 代码在这里 Widget build BuildContext context return Con
  • Flutter 为什么环绕行时 Wrap 不起作用?

    我试图将一些内容包装在 flutter 中 但没有成功 我发现我无法像使用芯片或文本小部件那样换行 有人知道为什么吗 这是三组 Rows 每组都有一个图标和一个文本 并排放置 但在较小的屏幕中它会溢出 因为没有足够的空间 宽度 我希望当当前
  • 显示菜单位置 Flutter

    我有一个 GridView 小部件 其中包含一些用 GestureDetector 包裹的 GridTiles 当我长按它时 尝试显示一个菜单以删除 GridTile 一切都很好 除了我希望从我拥有的点开始显示该菜单点击的不是应用程序的顶部
  • 构建 FutureBuilder 时抛出 _TypeError(脏,状态:_FutureBuilderState 类型“Null”不是类型“List”的子类型

    我已经处理这个问题很长时间了 我正在尝试解析 JSON 并将其转换为列表视图 我收到响应正文 它也被转换为列表 但它向未来的构建器发送 null 我收到此错误 小部件库捕获的异常 构建 FutureBuilder dirty state F
  • 错误:未为类“BuildContext”定义方法“inheritFromWidgetOfExactType”

    今天编译flutter项目的时候出现了这样的错误 This will generate a JSON format file containing all messages that need to be translated pub ca
  • flutter 中 Future.delayed 与 Timer 有什么区别

    我想知道延迟代码执行的 Future delayed 和 Timer 方法之间的区别 两者似乎都做同样的事情 未来 延迟 Future delayed const Duration milliseconds 500 code VS Time
  • 是否可以在flutter中开发移动键盘应用程序

    我们想要开发具有一些独特功能 例如在键盘上翻译 的移动键盘应用程序 第三方键盘 我们想知道是否有一种方法可以同时为 IOS 和 Android 开发一次 使用 Flutter 或者其他解决方案 对此有一个长的和一个短的答案 简短的回答基本上
  • 渲染时 Flutter SVG 延迟

    我在行中显示 SVG 文件形式的图像和文本 由于某些原因 svg 图像的渲染速度比屏幕的其余部分慢 从而导致延迟 这不利于用户体验 这种延迟正常吗 我该怎么做才能使整个屏幕同时渲染 Row mainAxisAlignment MainAxi
  • 如何在列表视图中滚动添加更多项目?

    这里的代码当前加载了存储在 Firestore 集合中的所有啤酒 我如何最初只加载 10 个啤酒 然后当用户向下滚动并到达 10 个啤酒列表的末尾时 它应该加载最后一次酿造后还有 10 杯 并且酿造应根据时间戳进行排序 class Brew
  • 带操作按钮的颤动本地通知

    我在我的 flutter 项目中尝试了 flutter 本地通知插件 它在简单通知上工作正常 但我需要带有操作按钮的通知功能 请帮助我或建议我实现此功能 不幸的是 flutter local notifications 插件尚不支持操作按钮
  • 如何在 Flutter App 中按时间注销?

    如果用户在登录后对应用程序没有反应或不活动超过 5 分钟 我需要从应用程序中注销用户 该应用程序将转到主登录页面 我尝试实施给定的解决方案here https stackoverflow com questions 52602606 how
  • Flutter 应用程序在 iOS 平台的 firebase 电话身份验证中崩溃

    我在我的项目中实现了 Firebase Phone auth 在 Android 端 一切正常 但对于 iOS 端 当我尝试从我的端发送验证码时 应用程序崩溃并失去连接 我已在下面提交了我的代码 主程序 dart class MyApp e
  • 如何将 Flutter 应用连接到 tcp 套接字服务器?

    我很难将 Flutter 应用程序连接到服务器上的网络 tcp 套接字 我知道我必须使用某种中间选项 以便在 tcp 套接字到 flutter 以及 Flutter 到 tcp 套接字之间转换数据 任何想法 信息如何实现这一目标 问题是如何
  • Android Studio 无法运行 Xcode 模拟器

    我正在尝试使用 Xcode iPhone 模拟器模拟我的 Flutter 应用程序 但收到此错误 在升级 Android Studio 和 Xcode 之前 它运行良好 Launching lib main dart on iPhone X
  • 从后台恢复后,Flutter GoogleMap 为空白

    我遇到以下问题 我的 Flutter 应用程序使用 GoogleMap 地图最初加载得很好 但是 如果我将应用程序置于后台并稍后恢复 地图将保持空白 Google 徽标仍然显示 就像未指定 API 密钥时发生的情况一样 我的多边形叠加层也不
  • 使用 Flutter 3.10 / Dart 3.0 进行 VS Code 调试<优化>

    在最新的 颤振 升级 之后 我在 VS Code 调试期间查看某些变量时遇到问题 如何在悬停时查看变量的内容而不是获取此内容 Screenshot of hovering variable 这仅发生在某些变量上 其他变量我可以正常查看内容
  • dart中解析对象(不支持的操作:无法添加到固定长度列表)

    我有一个用户对象 当用户登录 注册时 该对象保存到云 Firestore 数据库中 因此 当用户登录时 将从数据库中检索用户对象 并且一切正常 直到我尝试对列表 usersProject 执行 添加 操作 Add the new proje
  • 在 flutter 中强制重建有状态子部件

    假设我有一个主屏幕 有状态小部件 其中有一个变量count作为状态 在此主屏幕中 有一个按钮和另一个有状态小部件 我们称之为MyListWidget MyListWidget初始化它自己的小部件initState取决于的值count多变的
  • NoSuchMethodError:尝试调用非函数,例如 null:'dart.global.firebase.auth'

    Flutter 新手 我怀疑在尝试设置 Firebase Auth 时错过了一些非常简单的事情 一直在网上寻找解决方案 大多数人要求您仔细检查 firebase auth js 是否正确包含在 index html 文件中 这样就完成了 下

随机推荐