#flutter
Вопрос:
Я получаю следующую ошибку для своего кода
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.
If this message did not help you determine the problem, consider using debugDumpRenderTree():
https://flutter.dev/debugging/#rendering-layer
http://api.flutter.dev/flutter/rendering/debugDumpRenderTree.html
The affected RenderFlex is:
RenderFlex#35d16 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE(creator: Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#a73f2] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey#2021f] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#2e976] ← RepaintBoundary ← CustomPaint-[GlobalKey#46173] ← ⋯, parentData: (can use size), constraints: BoxConstraints(w=360.0, 0.0<=h<=Infinity), size: Size(360.0, 61.0), direction: vertical, mainAxisAlignment: start, mainAxisSize: max, crossAxisAlignment: center, verticalDirection: down)
The creator information is set to:
Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#a73f2] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey#2021f] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#2e976] ← RepaintBoundary ← CustomPaint-[GlobalKey#46173] ← ⋯
The nearest ancestor providing an unbounded width constraint is: _RenderSingleChildViewport#f779b NEEDS-LAYOUT NEEDS-PAINT:
needs compositing
creator: _SingleChildViewport ← IgnorePointer-[GlobalKey#a73f2] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey#2021f] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#2e976] ← RepaintBoundary ← CustomPaint-[GlobalKey#46173] ← _RawMouseRegion ← ⋯
parentData: (can use size)
constraints: BoxConstraints(w=360.0, h=467.2)
layer: OffsetLayer#5728c
size: Size(360.0, 467.2)
See also: https://flutter.dev/layout/
If none of the above helps enough to fix this problem, please don't hesitate to file a bug:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
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.
If this message did not help you determine the problem, consider using debugDumpRenderTree():
https://flutter.dev/debugging/#rendering-layer
http://api.flutter.dev/flutter/rendering/debugDumpRenderTree.html
The affected RenderFlex is:
RenderFlex#35d16 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE(creator: Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#a73f2] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey#2021f] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#2e976] ← RepaintBoundary ← CustomPaint-[GlobalKey#46173] ← ⋯, parentData: (can use size), constraints: BoxConstraints(w=360.0, 0.0<=h<=Infinity), size: Size(360.0, 61.0), direction: vertical, mainAxisAlignment: start, mainAxisSize: max, crossAxisAlignment: center, verticalDirection: down)
The creator information is set to:
Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#a73f2] ← Semantics ← Listener ←
_GestureSemantics ← RawGestureDetector-[LabeledGlobalKey#2021f] ←
Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#2e976] ← RepaintBoundary ←
CustomPaint-[GlobalKey#46173] ← ⋯
The nearest ancestor providing an unbounded width constraint is: _RenderSingleChildViewport#f779b NEEDS-LAYOUT NEEDS-PAINT:
needs compositing
creator: _SingleChildViewport ← IgnorePointer-[GlobalKey#a73f2] ← Semantics ← Listener ←
_GestureSemantics ← RawGestureDetector-[LabeledGlobalKey#2021f] ←
Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#2e976] ← RepaintBoundary ←
CustomPaint-[GlobalKey#46173] ← _RawMouseRegion ← ⋯
parentData: (can use size)
constraints: BoxConstraints(w=360.0, h=467.2)
layer: OffsetLayer#5728c
size: Size(360.0, 467.2)
See also: https://flutter.dev/layout/
If none of the above helps enough to fix this problem, please don't hesitate to file a bug:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
The relevant error-causing widget was:
Column
/lib/screens/added_challenge_info.dart:54:34
When the exception was thrown, this was the stack:
dart:sdk_internal 5348:11 throw_
packages/flutter/src/rendering/flex.dart 926:9
packages/flutter/src/rendering/flex.dart 928:14 performLayout
packages/flutter/src/rendering/object.dart 1779:7 layout
packages/flutter/src/widgets/single_child_scroll_view.dart 581:7 performLayout
packages/flutter/src/rendering/object.dart 1636:7 [_layoutWithoutResize]
packages/flutter/src/rendering/object.dart 881:17 flushLayout
packages/flutter/src/rendering/binding.dart 462:19 drawFrame
packages/flutter/src/widgets/binding.dart 876:13 drawFrame
packages/flutter/src/rendering/binding.dart 328:5 [_handlePersistentFrameCallback]
packages/flutter/src/scheduler/binding.dart 1144:15 [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1082:9 handleDrawFrame
packages/flutter/src/scheduler/binding.dart 998:5 [_handleDrawFrame]
dart:sdk_internal 186345:7 invoke
dart:sdk_internal 166271:15 invokeOnDrawFrame
dart:sdk_internal 183434:55
The following RenderObject was being processed when the exception was fired: RenderFlex#35d16 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
creator: Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#a73f2] ← Semantics ← Listener ←
_GestureSemantics ← RawGestureDetector-[LabeledGlobalKey#2021f] ←
Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#2e976] ← RepaintBoundary ←
CustomPaint-[GlobalKey#46173] ← ⋯
parentData: (can use size)
constraints: BoxConstraints(w=360.0, 0.0<=h<=Infinity)
size: Size(360.0, 61.0)
direction: vertical
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: center
verticalDirection: down
This RenderObject had the following descendants (showing up to depth 5):
child 1: RenderPadding#0a03f relayoutBoundary=up2 NEEDS-PAINT
child: RenderFlex#94b34 relayoutBoundary=up3 NEEDS-PAINT
child 1: RenderSemanticsAnnotations#7d3ea relayoutBoundary=up4 NEEDS-PAINT
child: RenderMouseRegion#ff92e relayoutBoundary=up5 NEEDS-PAINT
child: RenderSemanticsAnnotations#ca9a7 relayoutBoundary=up6 NEEDS-PAINT
child 2: RenderSemanticsAnnotations#46b18 relayoutBoundary=up4 NEEDS-PAINT
child: RenderMouseRegion#11cf7 relayoutBoundary=up5 NEEDS-PAINT
child: RenderSemanticsAnnotations#c1a5a relayoutBoundary=up6 NEEDS-PAINT
child 2: RenderStack#1baf2 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child 1: RenderStack#6b82e NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child 1: RenderRepaintBoundary#6d25a NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child: RenderSemanticsGestureHandler#cced9 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child: RenderPointerListener#06fa5 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child 2: RenderLimitedBox#fc4c2 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child: RenderConstrainedBox#ec341 NEEDS-LAYOUT NEEDS-PAINT
child 2: RenderLimitedBox#ceb62 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child: RenderConstrainedBox#71b41 NEEDS-LAYOUT NEEDS-PAINT
════════════════════════════════════════════════════════════════════════════════════════════════════
Unexpected null value.
Another exception was thrown: Unexpected null value.
Cannot hit test a render box that has never been laid out.
The hitTest() method was called on this RenderBox: RenderStack#1baf2 NEEDS-LAYOUT NEEDS-PAINT:
needs compositing
creator: Stack ← RankedList ← Expanded ← Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#a73f2] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey#2021f] ← Listener ← _ScrollableScope ← ⋯
parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
constraints: MISSING
size: MISSING
alignment: Alignment.topCenter
textDirection: ltr
fit: loose
Unfortunately, this object's geometry is not known at this time, probably because it has never been laid out. This means it cannot be accurately hit-tested.
If you are trying to perform a hit test during the layout phase itself, make sure you only hit test nodes that have completed layout (e.g. the node's children, after their layout() method has been called).
Another exception was thrown: Cannot hit test a render box that has never been laid out.
Cannot hit test a render box that has never been laid out.
The hitTest() method was called on this RenderBox: RenderStack#1baf2 NEEDS-LAYOUT NEEDS-PAINT:
needs compositing
creator: Stack ← RankedList ← Expanded ← Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#a73f2] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey#2021f] ← Listener ← _ScrollableScope ← ⋯
parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
constraints: MISSING
size: MISSING
alignment: Alignment.topCenter
textDirection: ltr
fit: loose
Unfortunately, this object's geometry is not known at this time, probably because it has never been laid out. This means it cannot be accurately hit-tested.
If you are trying to perform a hit test during the layout phase itself, make sure you only hit test nodes that have completed layout (e.g. the node's children, after their layout() method has been called).
Assertion failed: /libmouse_tracker.dart:201:12
!_debugDuringDeviceUpdate
is not true
Another exception was thrown: Assertion failed: file:///home/builder/hotbuilder/packages/flutter/lib/src/rendering/mouse_tracker.dart:201:12
Cannot hit test a render box that has never been laid out.
The hitTest() method was called on this RenderBox: RenderStack#1baf2 NEEDS-LAYOUT NEEDS-PAINT:
needs compositing
creator: Stack ← RankedList ← Expanded ← Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#a73f2] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey#2021f] ← Listener ← _ScrollableScope ← ⋯
parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
constraints: MISSING
size: MISSING
alignment: Alignment.topCenter
textDirection: ltr
fit: loose
Unfortunately, this object's geometry is not known at this time, probably because it has never been laid out. This means it cannot be accurately hit-tested.
If you are trying to perform a hit test during the layout phase itself, make sure you only hit test nodes that have completed layout (e.g. the node's children, after their layout() method has been called).
Мой код приведен ниже:
Я видел из подобных сообщений, что подход, который я могу применить, заключается в том, чтобы обернуть контейнер в прокручиваемый с помощью расширенного, так было сделано с _buildLeaderboard, но это все еще не исправило ошибку… Мне интересно, не потому ли это, что я добавляю RankedList в прокручиваемый список, так как в его pubdev написано: «RankedList использует контроллер прокрутки за кулисами, поэтому вы не можете добавить свой собственный контроллер прокрутки в список на данный момент»… Если да, то как я могу исправить эту проблему?
Спасибо вам, как всегда!
class AddedChallengeInfo extends StatefulWidget {
final Challenge challenge;
const AddedChallengeInfo({required this.challenge});
@override
_AddedChallengeInfoState createState() => _AddedChallengeInfoState();
}
class _AddedChallengeInfoState extends State<AddedChallengeInfo> {
int selectedId = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xffFFAAA6),
appBar: AppBar(
iconTheme: IconThemeData(
color: Color(0xff999999),
),
backgroundColor: Colors.transparent,
actions: [
IconButton(
icon: Icon(
FontAwesomeIcons.trashAlt,
size: 20,
color: Color(0xff999999),
), // Icon
onPressed: () {
Navigator.pop(context, true);
},
),
SizedBox(width: 20)
]),
body: Stack(children: [
ChallengeHeader(challenge: widget.challenge),
DraggableScrollableSheet(
initialChildSize: 0.8,
minChildSize: 0.8,
maxChildSize: 1.0,
builder: (BuildContext context, myScrollController) {
return ClipRRect(
borderRadius: BorderRadius.vertical(top: Radius.circular(30.0)),
child: Container(
color: Colors.white,
child: SingleChildScrollView(
controller: myScrollController,
child: Column(children: [
_buildScreenSelector(),
selectedId == 0 ? SizedBox() : _buildLeaderboard(),
])),
));
})
]));
}
Widget _buildScreenSelector() {
return Padding(
padding: const EdgeInsets.only(left: 30, right: 30, top: 10, bottom: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_buildHeaderSelectorButton(0, "Intro"),
_buildHeaderSelectorButton(1, "Leaderboard"),
],
),
);
}
Widget _buildLeaderboard() {
return Expanded(
child: RankedList(
itemBuilder: (context, index) {
return Container(
height: 500,
color: index 1 == 2 ? Colors.green : Colors.white,
child: ListTile(
title: Text(
'${index 1}',
style: Theme.of(context).textTheme.headline6,
),
));
},
itemCount: 3,
rank: 2,
itemHeight: 56,
topItem: Container(
color: Colors.green,
child: ListTile(
title: Text(
'25',
style: Theme.of(context).textTheme.headline6,
),
),
),
bottomItem: Container(
color: Colors.green,
child: ListTile(
title: Text(
'25',
style: Theme.of(context).textTheme.headline6,
),
),
),
showBottom: false,
));
}
Widget _buildSelectorButton(int id, String t) {
return InkWell(
onTap: () {
setState(() {
selectedId = id;
});
},
child: Container(
alignment: Alignment.center,
width: 56,
height: 21,
child: Text(
'$t',
style: TextStyle(color: id == selectedId ? Colors.white : Colors.black),
),
decoration: BoxDecoration(
color: id == selectedId ? Colors.black : Colors.white,
borderRadius: BorderRadius.circular(20),
),
),
);
}
}
Комментарии:
1. Как сказано также в исключении, вместо использования расширенного, возможно, вам следует использовать
Flexible
.2. @Pushpendra не сработало… не знаю, почему
3. И как насчет mainAxisSize тоже в колонке до минимума
4. @Pushpendra вы не можете использовать mainaxissize на flexible, и нет столбца, в который можно добавить mainaxissize
5. Я имел в виду, добавив это в колонку, а не в виджет flexbile.