在我的应用程序中,我已经使用谷歌地图。
我试图设置我的布局使用堆栈小部件。
使用堆栈小部件,它填补了谷歌地图在整个屏幕上。
然后在顶部,搜索栏的位置。
下面的搜索栏,我想显示列表视图,这将作为是自动完成搜索谷歌的地方,根据用户的文本。
问题是当我添加列表视图的布局,它给出了错误。
这就是错误。
I/flutter ( 6057): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 6057): The following assertion was thrown during performLayout():
I/flutter ( 6057): RenderFlex children have non-zero flex but incoming height constraints are unbounded.
I/flutter ( 6057): When a column is in a parent that does not provide a finite height constraint, for example if it is
I/flutter ( 6057): in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a
I/flutter ( 6057): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining
I/flutter ( 6057): space in the vertical direction.
I/flutter ( 6057): These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
I/flutter ( 6057): cannot simultaneously expand to fit its parent.
I/flutter ( 6057): Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible
I/flutter ( 6057): children (using Flexible rather than Expanded). This will allow the flexible children to size
I/flutter ( 6057): themselves to less than the infinite remaining space they would otherwise be forced to take, and
I/flutter ( 6057): then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum
I/flutter ( 6057): constraints provided by the parent.
I/flutter ( 6057): If this message did not help you determine the problem, consider using debugDumpRenderTree():
I/flutter ( 6057): https://flutter.dev/debugging/#rendering-layer
I/flutter ( 6057): http://api.flutter.dev/flutter/rendering/debugDumpRenderTree.html
I/flutter ( 6057): The affected RenderFlex is:
I/flutter ( 6057): RenderFlex#7c916 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE(creator: Column ← Positioned ← Stack ← _BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#dd38c ink renderer] ← NotificationListener<LayoutChangedNotification> ← ⋯, parentData: top=200.0; offset=Offset(0.0, 0.0) (can use size), constraints: BoxConstraints(unconstrained), size: MISSING, direction: vertical, mainAxisAlignment: start, mainAxisSize: max, crossAxisAlignment: center, verticalDirection: down)
I/flutter ( 6057): The creator information is set to:
I/flutter ( 6057): Column ← Positioned ← Stack ← _BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ←
I/flutter ( 6057): CustomMultiChildLayout ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ←
I/flutter ( 6057): _InkFeatures-[GlobalKey#dd38c ink renderer] ← NotificationListener<LayoutChangedNotification> ← ⋯
I/flutter ( 6057): The nearest ancestor providing an unbounded width constraint is: RenderStack#cff5c relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
I/flutter ( 6057): creator: Stack ← _BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ←
I/flutter ( 6057): CustomMultiChildLayout ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ←
I/flutter ( 6057): _InkFeatures-[GlobalKey#dd38c ink renderer] ← NotificationListener<LayoutChangedNotification> ←
I/flutter ( 6057): PhysicalModel ← AnimatedPhysicalModel ← ⋯
I/flutter ( 6057): parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.body (can use size)
I/flutter ( 6057): constraints: BoxConstraints(0.0<=w<=392.7, 0.0<=h<=759.3)
I/flutter ( 6057): size: Size(392.7, 759.3)
I/flutter ( 6057): alignment: AlignmentDirectional.topStart
I/flutter ( 6057): textDirection: ltr
I/flutter ( 6057): fit: loose
I/flutter ( 6057): overflow: clip
I/flutter ( 6057): See also: https://flutter.dev/layout/
I/flutter ( 6057): If none of the above helps enough to fix this problem, please don't hesitate to file a bug:
I/flutter ( 6057): https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter ( 6057):
I/flutter ( 6057): The relevant error-causing widget was:
I/flutter ( 6057): Column file:///E:/ARSALAN_STUFF/PROJECTS_Codegasm/googlemap/flutter_app/lib/main.dart:211:24
I/flutter ( 6057):
I/flutter ( 6057): When the exception was thrown, this was the stack:
I/flutter ( 6057): #0 RenderFlex.performLayout.<anonymous closure> (package:flutter/src/rendering/flex.dart:693:11)
I/flutter ( 6057): #1 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:720:10)
I/flutter ( 6057): #2 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #3 RenderStack.layoutPositionedChild (package:flutter/src/rendering/stack.dart:487:11)
I/flutter ( 6057): #4 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:583:30)
I/flutter ( 6057): #5 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #6 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:171:11)
I/flutter ( 6057): #7 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:484:7)
I/flutter ( 6057): #8 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:240:7)
I/flutter ( 6057): #9 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:399:14)
I/flutter ( 6057): #10 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #11 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #12 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #13 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #14 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1248:11)
I/flutter ( 6057): #15 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #16 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #17 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #18 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #19 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #20 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #21 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #22 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #23 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #24 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #25 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #26 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #27 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #28 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #29 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #30 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #31 RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3225:13)
I/flutter ( 6057): #32 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #33 _RenderTheatre.performLayout (package:flutter/src/widgets/overlay.dart:700:15)
I/flutter ( 6057): #34 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #35 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #36 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #37 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #38 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #39 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #40 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #41 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #42 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #43 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter ( 6057): #44 RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter ( 6057): #45 RenderView.performLayout (package:flutter/src/rendering/view.dart:167:13)
I/flutter ( 6057): #46 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1630:7)
I/flutter ( 6057): #47 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:887:18)
I/flutter ( 6057): #48 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:402:19)
I/flutter ( 6057): #49 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:884:13)
I/flutter ( 6057): #50 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:284:5)
I/flutter ( 6057): #51 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1113:15)
I/flutter ( 6057): #52 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1052:9)
I/flutter ( 6057): #53 SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:861:7)
I/flutter ( 6057): (elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
I/flutter ( 6057):
I/flutter ( 6057): The following RenderObject was being processed when the exception was fired: RenderFlex#7c916 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
I/flutter ( 6057): creator: Column ← Positioned ← Stack ← _BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ←
I/flutter ( 6057): CustomMultiChildLayout ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ←
I/flutter ( 6057): _InkFeatures-[GlobalKey#dd38c ink renderer] ← NotificationListener<LayoutChangedNotification> ← ⋯
I/flutter ( 6057): parentData: top=200.0; offset=Offset(0.0, 0.0) (can use size)
I/flutter ( 6057): constraints: BoxConstraints(unconstrained)
I/flutter ( 6057): size: MISSING
I/flutter ( 6057): direction: vertical
I/flutter ( 6057): mainAxisAlignment: start
I/flutter ( 6057): mainAxisSize: max
I/flutter ( 6057): crossAxisAlignment: center
I/flutter ( 6057): verticalDirection: down
I/flutter ( 6057): This RenderObject had the following descendants (showing up to depth 5):
I/flutter ( 6057): child 1: RenderRepaintBoundary#7ca29 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 6057): child: RenderCustomPaint#abde1 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 6057): child: RenderRepaintBoundary#aee8f NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 6057): child: _RenderScrollSemantics#1ab77 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 6057): child: RenderPointerListener#5c802 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 6057): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter ( 6057): Another exception was thrown: RenderBox was not laid out: RenderFlex#7c916 relayoutBoundary=up2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 6057): Another exception was thrown: NoSuchMethodError: The method '>' was called on null.
I/mple.flutterap( 6057): NativeAlloc concurrent copying GC freed 29925(1495KB) AllocSpace objects, 2(104KB) LOS objects, 30% free, 13MB/19MB, paused 1.018ms total 1.072s
W/System ( 6057): A resource failed to call release.
I/flutter ( 6057): Another exception was thrown: NoSuchMethodError: The method '>' was called on null.
D/HostConnection( 6057): HostConnection::get() New Host Connection established 0xb790a9c0, tid 7171
D/HostConnection( 6057): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_2
I/mple.flutterap( 6057): NativeAlloc concurrent copying GC freed 10798(437KB) AllocSpace objects, 0(0B) LOS objects, 30% free, 13MB/19MB, paused
这是布局。
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
GoogleMap(
// markers: _markers,
// polylines:polyline,
onMapCreated: onMapCreated,
// polylines: Set.from(polyline),
// myLocationEnabled: true,
initialCameraPosition: CameraPosition(
target: _pinposition,
zoom: 10.0,
bearing: 45.0,
tilt: 45.0
),
markers: Set.from(allMarkers),
polylines: _polyLines,
),
Positioned(
top: 30.0,
right: 15.0,
left: 15.0,
child: Container(
height: 50.0,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.white
),
child: TextField(
decoration: InputDecoration(
hintText: 'Enter address',
border: InputBorder.none,
contentPadding: EdgeInsets.only(left: 15.0,top: 15.0),
suffixIcon: IconButton(
icon: Icon(Icons.search),
onPressed: searchandNavigate,
iconSize: 30.0,
)
),
onTap: () async {
Prediction p = await PlacesAutocomplete.show(
context: context, apiKey: apikey);
displayPrediction(p);
},
onChanged: (val){
setState(() {
searchAddress = val;
});
},
),
),
),
Positioned(
top: 200,
child: Column(
children: <Widget>[
Expanded(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
//shrinkWrap: true,
itemCount: _placesList.length,
itemBuilder: (BuildContext context, int index) =>
buildPlaceCard(context, index),
),
),
],
),
)
],
),
);
}
Widget buildPlaceCard(BuildContext context, int index) {
Container(
child: Padding(
padding: const EdgeInsets.only(
left: 8.0,
right: 8.0,
),
child: Card(
child: InkWell(
child: Row(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Text(_placesList[index].name, style: TextStyle(fontSize: 30.0)),
],
),
Row(
children: <Widget>[
Text("Average Budget \$${_placesList[index].averageBudget.toStringAsFixed(2)}"),
],
),
],
),
),
),
Column(
children: <Widget>[
Placeholder(
fallbackHeight: 80,
fallbackWidth: 80,
),
],
)
],
),
onTap: () {
String placename = _placesList[index].name;
// TODO maybe pass the trip average budget through here too...
// that would need to be added to the Trip object
},
),
),
),
);
}
buildPlaceCard方法不返回widget:)
这段代码将把你的listview定位在你的文本输入下面。
Positioned(
left: 15,
right: 15,
top: 80,
height: 40, // UP to you
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
//shrinkWrap: true,
itemCount: 20,
itemBuilder:
(BuildContext context,
int index) =>
buildPlaceCard(context, index),
),
)
你的buildPlaceCard方法应该是这样的,我已经去掉了不必要的container夫妇的行cols。
Widget buildPlaceCard(BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.only(
left: 8.0,
right: 8.0,
),
child: Card(
child: InkWell(
child: Row(
children: <Widget>[
Expanded(
child: Padding(
padding:
const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
Text(
_placesList[index].name,
style: TextStyle(
fontSize: 30.0)),
Text("Average Budget \$${_placesList[index].averageBudget.toStringAsFixed(2)}"),
],
),
),
),
Placeholder(
fallbackHeight: 80,
fallbackWidth: 80,
),
],
),
onTap: () {
String placename = "SOME NAME";
// TODO maybe pass the trip average budget through here too...
// that would need to be added to the Trip object
},
),
),
);
}
第一:你不需要添加列和listView。第二:只需要设置固定的高度或者设置底部的位置,比如说:"你可以把 listView 包在固定的高度内,比如说:"你可以把 listView 包在固定的高度内,比如说:"你可以把 listView 包在固定的高度内,比如说:"你可以把 listView 包在固定的高度内,比如说:"你可以把 listView 包在固定的高度内,比如说:"你可以把 listView 包在固定的高度内,比如说:"你可以把 listView 包在固定的高度内,比如说:"你可以把 listView 包在固定的高度内,比如说:"你可以把 listView 包在固定的高度内,比如说:"你可以把 listView 包在固定的高度内,比如说:"你可以把 listView 包在固定的高度内,比如说:"你可以把 listView 包在固定的高度内。
Positioned(
top: 200,
bottom: 0,//or what you want or you can wrap listView inside fixed height continer
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
//shrinkWrap: true,
itemCount: _placesList.length,
itemBuilder: (BuildContext context, int index) =>
buildPlaceCard(context, index),
),
)
或者你可以把listView包裹在固定的高度内,例如:
Positioned(
top: 200,
child: Container(
height: 50.0,//or any thing you can USE MEDIA QUERY
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
//shrinkWrap: true,
itemCount: _placesList.length,
itemBuilder: (BuildContext context, int index) =>
buildPlaceCard(context, index),
),
),
)