当我将窗口小部件标题固定在窗口上时,我会收到此日志,我不知道他为什么得到此日志。 那是我的日志:
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: ...
),
]),
]),
),
),
);
}
}
答案 0 :(得分:0)
我找到了答案,我应该只从设备屏幕的宽度中加上高度和宽度。
我希望能对其他人有所帮助,像我一样学会颤抖:)
@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(),
),
]),
),
);
}
}