flutter - Hero 动画产生 RenderBox 溢出
问题描述
我正在使用该Hero
组件在两个页面之间创建动画。该Hero
组件用于包装一个Image
小部件(没问题)和一个Container
小部件(有问题)。
抛出以下溢出错误:
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞════════════════════════════════════════
I/flutter ( 4256): The following message was thrown during layout:
I/flutter ( 4256): A RenderFlex overflowed by 104 pixels on the right.
第一页
Positioned(
width: MediaQuery.of(context).size.width * 0.7,
height: MediaQuery.of(context).size.height * 0.45,
top: 160.0,
left: MediaQuery.of(context).size.width * 0.04,
child: Hero(
tag: i.id,
child: Container( ...)
)
)
第二页
Hero(
tag: this.i.departure,
child: Container(
margin: EdgeInsets.only(top: MediaQuery.of(context).size.height * 0.25),
height: MediaQuery.of(context).size.height,
decoration: cardDecoration,
),
),
解决方案
原因不是Container
小部件本身,而是内容。
您分享的 GIF 清楚地表明,它的Text
内部没有像往常一样渲染,而是过大。这是由缺少的Material
祖先引起的,该祖先将包含正确InheritedWidget
渲染所需的 ' Text
(它丢失是因为Hero
将child
您提供的' 放在 ' 中Overlay
并且它没有Material
从你的' 继承 a Scaffold
)。
因此,您需要添加一个Material
小部件来解决您的问题。
Hero(
tag: tag,
child: Material(
type: MaterialType.transparency,
child: .. // in your cause `Container(..)`
),
)
我提供MaterialType.transparency
以防止它影响底层 UI。
推荐阅读
- reactjs - 面包屑反应代码不起作用,我该如何解决?
- haskell - 如何将 `throwM` 与 `Except` 一起使用?
- bazel - 带有 protobuf / gRPC-gateway / golang 的 bazel - 入门
- angular - 将带有 rxjs 的 Angular 5 模块导入 Angular 8 应用程序
- ios - Firebase Firestore collectionGroup()查询方法无法识别 - swift
- acumatica - 如何在报表设计器中通过 URL 引用外部图像?
- php - MySQL阻止用户从其他用户那里获取代码
- excel - 在单元格中搜索特定文本并从列表中返回匹配的文本
- kotlin - Kotlin 结合使用箭头、lamda、?、. , 然后让。什么意思?
- python - Pandas to_sql 设置列类型