[英]Flutter Positioned Element to flex it, what main this log?
I get this log when I would the Widget Header Fixed on the Window, I don't why he get this. 当我在窗口上修复Widget标题时,我得到了这个日志,我不知道他为什么会这样做。 that is my log:
那是我的日志:
I/flutter ( 9657): The following assertion was thrown during performLayout():
I/flutter ( 9657): RenderFlex children have non-zero flex but incoming width constraints are unbounded.
I/flutter ( 9657): When a row is in a parent that does not provide a finite width constraint, for example if it is in a
I/flutter ( 9657): horizontal scrollable, it will try to shrink-wrap its children along the horizontal axis. Setting a
I/flutter ( 9657): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining
I/flutter ( 9657): space in the horizontal direction.
I/flutter ( 9657): These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
I/flutter ( 9657): cannot simultaneously expand to fit its parent.
I/flutter ( 9657): Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible
I/flutter ( 9657): children (using Flexible rather than Expanded). This will allow the flexible children to size
I/flutter ( 9657): themselves to less than the infinite remaining space they would otherwise be forced to take, and
I/flutter ( 9657): then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum
I/flutter ( 9657): constraints provided by the parent.
I/flutter ( 9657): The affected RenderFlex is:
I/flutter ( 9657): RenderFlex#b7f40 relayoutBoundary=up9 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 9657): The creator information is set to:
I/flutter ( 9657): Row ← Padding ← Container ← Padding ← DecoratedBox ← ConstrainedBox ← Padding ← Container ← Align
I/flutter ( 9657): ← ClipRect ← Header ← Container ← ⋯
I/flutter ( 9657): The nearest ancestor providing an unbounded width constraint is:
I/flutter ( 9657): RenderStack#9cf16 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 9657): creator: Stack ← Container ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout
I/flutter ( 9657): ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#ccab9
I/flutter ( 9657): ink renderer] ← NotificationListener<LayoutChangedNotification> ← PhysicalModel ←
I/flutter ( 9657): AnimatedPhysicalModel ← ⋯
I/flutter ( 9657): parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.body (can use size)
I/flutter ( 9657): constraints: BoxConstraints(0.0<=w<=411.4, 0.0<=h<=774.9)
I/flutter ( 9657): size: Size(411.4, 774.9)
I/flutter ( 9657): alignment: AlignmentDirectional.topStart
I/flutter ( 9657): textDirection: ltr
I/flutter ( 9657): fit: loose
I/flutter ( 9657): overflow: clip
I/flutter ( 9657): See also: https://flutter.io/layout/
I/flutter ( 9657): If this message did not help you determine the problem, consider using debugDumpRenderTree():
I/flutter ( 9657): https://flutter.io/debugging/#rendering-layer
I/flutter ( 9657): http://docs.flutter.io/flutter/rendering/debugDumpRenderTree.html
I/flutter ( 9657): If none of the above helps enough to fix this problem, please don't hesitate to file a bug:
I/flutter ( 9657): https://github.com/flutter/flutter/issues/new?template=BUG.md
Performing hot reload...
Syncing files to device Android SDK built for x86...
I/flutter ( 9657): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 9657): The following assertion was thrown during performLayout():
I/flutter ( 9657): RenderFlex children have non-zero flex but incoming width constraints are unbounded.
I/flutter ( 9657): When a row is in a parent that does not provide a finite width constraint, for example if it is in a
I/flutter ( 9657): horizontal scrollable, it will try to shrink-wrap its children along the horizontal axis. Setting a
I/flutter ( 9657): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining
I/flutter ( 9657): space in the horizontal direction.
I/flutter ( 9657): These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
I/flutter ( 9657): cannot simultaneously expand to fit its parent.
I/flutter ( 9657): Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible
I/flutter ( 9657): children (using Flexible rather than Expanded). This will allow the flexible children to size
I/flutter ( 9657): themselves to less than the infinite remaining space they would otherwise be forced to take, and
I/flutter ( 9657): then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum
I/flutter ( 9657): constraints provided by the parent.
I/flutter ( 9657): The affected RenderFlex is:
I/flutter ( 9657): RenderFlex#b7f40 relayoutBoundary=up9 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 9657): The creator information is set to:
I/flutter ( 9657): Row ← Padding ← Container ← Padding ← DecoratedBox ← ConstrainedBox ← Padding ← Container ← Align
I/flutter ( 9657): ← ClipRect ← Header ← Container ← ⋯
I/flutter ( 9657): The nearest ancestor providing an unbounded width constraint is:
I/flutter ( 9657): RenderStack#9cf16 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 9657): creator: Stack ← Container ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout
I/flutter ( 9657): ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#ccab9
I/flutter ( 9657): ink renderer] ← NotificationListener<LayoutChangedNotification> ← PhysicalModel ←
I/flutter ( 9657): AnimatedPhysicalModel ← ⋯
I/flutter ( 9657): parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.body (can use size)
I/flutter ( 9657): constraints: BoxConstraints(0.0<=w<=411.4, 0.0<=h<=774.9)
I/flutter ( 9657): size: Size(411.4, 774.9)
I/flutter ( 9657): alignment: AlignmentDirectional.topStart
I/flutter ( 9657): textDirection: ltr
I/flutter ( 9657): fit: loose
I/flutter ( 9657): overflow: clip
I/flutter ( 9657): See also: https://flutter.io/layout/
I/flutter ( 9657): If this message did not help you determine the problem, consider using debugDumpRenderTree():
I/flutter ( 9657): https://flutter.io/debugging/#rendering-layer
I/flutter ( 9657): http://docs.flutter.io/flutter/rendering/debugDumpRenderTree.html
I/flutter ( 9657): If none of the above helps enough to fix this problem, please don't hesitate to file a bug:
I/flutter ( 9657): https://github.com/flutter/flutter/issues/new?template=BUG.md
@override
Widget build(BuildContext context) {
//final Size screenSize = MediaQuery.of(context).size;
return WillPopScope(
onWillPop: () {
print('Back button pressed');
Navigator.pop(context, false);
return Future.value(false);
},
child: Scaffold(
body: Container(
child: Stack(children: <Widget>[
Positioned(
top: 0.0,
left: 0.0,
child: Container(child: Header(),),
),
ListView(children: <Widget>[
Container(
margin: EdgeInsets.all(20),
child: ...
),
]),
]),
),
),
);
}
}
I found the answer, I should only add the height and the width from the device screen width. 我找到了答案,我只应该从设备屏幕宽度添加高度和宽度。
I hope that helps others, that learn flutter like me :) 我希望能帮助别人,像我一样学习扑腾:)
@override
Widget build(BuildContext context) {
final Size screenSize = MediaQuery.of(context).size;
return WillPopScope(
onWillPop: () {
print('Back button pressed');
Navigator.pop(context, false);
return Future.value(false);
},
child: Scaffold(
body: Stack(children: <Widget>[
ListView(children: <Widget>[
...
]),
Positioned(
top: 20,
height: 100,
width: screenSize.width - 5,
left: 0,
child: Header(),
),
]),
),
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.