话不多说,直接丢报错信息,看看自己是否遇到:
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.
讲道理这段阅读理解已经告诉我们问题所在以及如何解决了,不放心可以配合一点源码阅读:在Flutter中可滚动组件的高度是无限(infinte)的,如源码所说:“provides its children with an infinite amount of space.”。这点特性和一些尽可能撑满可用空间的组件如Expanded互斥(Expand在flex布局中用以自动撑满剩下所有空间,其fit属性默认为FlexFit.tight)——因为在可滚动组件中使用Expanded时,Expanded可被分配的空间是无限的,无法渲染,于是抛错。
解决方式也是阅读理解后稍稍发散,不用Expanded这类fit属性为FlexFit.tight的组件就ok了,可以像提示所说的用Flexible代替Expanded(它的fit属性默认为fit属性默认为FlexFit.loose,呈现包裹性,刚好包裹子元素且不会超过最大可用宽(高)度),同时要注意,父Flex类型元素的mainAxisSize一定要设为MainAxisSize.min,否则也会报错,原理也是和上卖弄一样的可用空间无限问题。总结一下,其实垂直可滚动组件中,Column内部不可以也没必要使用任何none-zero的flex元素,所有chidren都用Container即可,如果强迫症也请使用Flexible,而非Expanded。
源码中也给出了正确实践的例子:
/// Widget build(BuildContext context) {
/// return LayoutBuilder(
/// builder: (BuildContext context, BoxConstraints viewportConstraints) {
/// return SingleChildScrollView(
/// child: ConstrainedBox(
/// constraints: BoxConstraints(
/// minHeight: viewportConstraints.maxHeight,
/// ),
/// child: Column(
/// mainAxisSize: MainAxisSize.min,
/// mainAxisAlignment: MainAxisAlignment.spaceAround,
/// children: <Widget>[
/// Container(
/// // A fixed-height child.
/// color: const Color(0xff808000), // Yellow
/// height: 120.0,
/// ),
/// Container(
/// // Another fixed-height child.
/// color: const Color(0xff008000), // Green
/// height: 120.0,
/// ),
/// ],
/// ),
/// ),
/// );
/// },
/// );
/// }
不过源码的实例也是面向特定场景的,实际运用中没必要完全按照例子来,只要做到上面总结的几点就没问题。
The following assertion was thrown building MyApp(dirty):
No M
ed
iaQuery widget ancestor found.
MyApp widgets require a M
ed
iaQuery widget ancestor.
The specific widget that could not find a M
ed
iaQuery ancestor was: MyApp
dirty
The ownership chain for the
原因及解决方案:造成此问题的原因,经过log验证,应该是TextField作为一个Widget,被滑
出
屏幕
,又滑回来,没有焦点的Widget的initState和build方法会被重新执行,也就是Widget会被重建,重建
时
原有的状
Render
Flex
child
ren have non-zero
flex
but incoming height constraints are unbound
ed
.
在
使用
Row和Column布局,在用了
Expand
ed
组件
时
报错
如下:在
报错
时
找到有效线索信息不多,因为结构创建和目前抛
出
来的
错误
还是有些差异,但其中有一句是如下:
大小太过于灵活,当
时
我的代码是Row()
组件
内还套了Row()
组件
的结构,从上方线索查找问题,这
时
候我就想到,我当
时
是直接在底层Row()
组件
中直接利用撑开
组件
Expand
ed
,而上一层父
组件
或某个N父
组件
大小是特别灵活没有定大小是弹性的。所以整体在
flutter
中无法计算大小来撑开布局,这
时
候我就把父
组件
上面的Row内也
使用
了
Expand
ed
完整
报错
信息:
Render
Flex
child
ren have non-zero
flex
but incoming height constraints are unbound
ed
.
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
child
当一个可
滚动
组件
中嵌套另一个可
滚动
组件
时
,会抛
出
如下
错误
信息:
The following assertion was thrown during performResize():
Vertical viewport was given unbound
ed
height.
Viewports
expand
in the scrolling direction to fill their cont...
编写
flutter
代码的
时
候,如果超
出
手机
屏幕
高度的话是会
出
错的,需要
使用
Single
Child
ScrollView
来包裹
Single
Child
ScrollView
和container用发一样, 直接包在外层就好了,里面是
child
’
它可以在主题内容超
出
Y轴的
时
候自动生成
滚动
条,类似overflow:auto
类似如下用法
return
Single
Child
ScrollView
(
ch...
问题描述:
flutter
混合开发
使用
video_player
时
,横竖屏切换
时
出
现生命周期重新加载, 视频从头播放的问题,并且因为生命周期重置了,
出
现跳转到
flutter
首页
原因分析:
原文地址:
https://blog.csdn.net/zhiyi2010/article/details/6570092
https://www.jianshu.com/p/2733e0b217f4
解决方案:
在AndroidManifest.xml文件中找到加载该
flutter
页面的对应的activity 添加