所以我试图重新创建UI模板。这是代码。我试图通过调用LatestViewed()添加另一个Horizontal GridView,但重新加载后无法渲染。我不知道呈现这种方式。我曾尝试使用扩展的窗口小部件和灵活的功能,但均无效果
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.blueGrey[50],
centerTitle: true,
title: Text(
'Engagement Rings',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
resizeToAvoidBottomPadding: false,
body: SingleChildScrollView(
child: Column(
children: <Widget>[
//Padding
new Padding(padding: const EdgeInsets.all(8.0),),
//Horizontal List
picSlides(),
//Padding
SizedBox(height: 10.0),
//Grid View
Container(
height: 100.0,
child: Column(
children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: Text(
'Engagement Rings',
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
),
Align(
alignment: Alignment.centerLeft,
child: Text(
'bhjbsdbskjksbdknbsdnbbskdbbsdk',
textAlign: TextAlign.left,
),
),
Align(
alignment: Alignment.bottomLeft,
child: RaisedButton(
onPressed: (){},
color: Colors.white,
child: Text(
'450.00 USD',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
)
],
),
),
SizedBox(height: 10.0),
sizeRow(),
SizedBox(height: 10.0),
Container(
margin: EdgeInsets.all(5.0),
padding: EdgeInsets.fromLTRB(5.0, 10.0, 5.0, 5.0),
height: 150.0,
color: Colors.grey,
child: Column(
children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: Container(
child: Text(
'Finance Calculator',
),
),
),
Expanded(
child:Row(
children: <Widget>[
Container(
color: Colors.white,
child: Center(
child: Text(
'0%',
style:TextStyle(
fontWeight: FontWeight.bold,
fontSize: 100.0,
),
),
),
),
Expanded(
child: Container(
color: Colors.white,
child: Center(
child: Text(
'From only 35.00 USD Per Month',
),
),
)
)
],
),
)
],
)
),
SizedBox(height: 10.0),
RecentlyViewed(),
]
),
)
);
这是显示的错误:
E/flutter (11292): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Cannot hit test a render box with no size.
E/flutter (11292): The hitTest() method was called on this RenderBox: RenderRepaintBoundary#68904 relayoutBoundary=up12 NEEDS-PAINT:
E/flutter (11292): needs compositing
E/flutter (11292): creator: RepaintBoundary ← NotificationListener<ScrollNotification> ← GlowingOverscrollIndicator ← Scrollable ← GridView ← RecentlyViewed ← Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#1d332] ← Semantics ← _PointerListener ← Listener ← ⋯
E/flutter (11292): parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
E/flutter (11292): constraints: BoxConstraints(0.0<=w<=411.4, 0.0<=h<=Infinity)
E/flutter (11292): layer: OffsetLayer#74c19 DETACHED
E/flutter (11292): size: MISSING
E/flutter (11292): metrics: 0.0% useful (1 bad vs 0 good)
E/flutter (11292): diagnosis: insufficient data to draw conclusion (less than five repaints)
E/flutter (11292): Although this node is not marked as needing layout, its size is not set.
E/flutter (11292): A RenderBox object must have an explicit size before it can be hit-tested. Make sure that the RenderBox in question sets its size during layout.
E/flutter (11292): #0 RenderBox.hitTest.<anonymous closure> (package:flutter/src/rendering/box.dart:2118:9)
E/flutter (11292): #1 RenderBox.hitTest (package:flutter/src/rendering/box.dart:2133:6)
E/flutter (11292): #2 RenderBoxContainerDefaultsMixin.defaultHitTestChildren.<anonymous closure> (package:flutter/src/rendering/box.dart:2488:24)
E/flutter (11292): #3 BoxHitTestResult.addWithRawTransform (package:flutter/src/rendering/box.dart:801:31)
E/flutter (11292): #4 BoxHitTestResult.addWithPaintOffset (package:flutter/src/rendering/box.dart:758:12)
E/flutter (11292): #5 RenderBoxContainerDefaultsMixin.defaultHitTestChildren (package:flutter/src/rendering/box.dart:2483:33)
E/flutter (11292): #6 RenderFlex.hitTestChildren (package:flutter/src/rendering/flex.dart:942:12)
E/flutter (11292): #7 RenderBox.hitTest (package:flutter/src/rendering/box.dart:2135:11)
E/flutter (11292): #8 _RenderSingleChildViewport.hitTestChildren.<anonymous closure> (package:flutter/src/widgets/single_child_scroll_view.dart:565:24)
E/flutter (11292): #9 BoxHitTestResult.addWithRawTransform (package:flutter/src/rendering/box.dart:801:31)
E/flutter (11292): #10 BoxHitTestResult.addWithPaintOffset (package:flutter/src/rendering/box.dart:758:12)
E/flutter (11292): #11 _RenderSingleChildViewport.hitTestChildren (package:flutter/src/widgets/single_child_scroll_view.dart:560:21)
E/flutter (11292): #12 RenderBox.hitTest (package:flutter/src/rendering/box.dart:2135:11)
E/flutter (11292): #13 RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:114:19)
E/flutter (11292): #14 RenderBox.hitTest (package:flutter/src/rendering/box.dart:2135:11)
E/flutter (11292): #15 RenderIgnorePointer.hitTest (package:flutter/src/rendering/proxy_box.dart:3064:31)
E/flutter (11292): #16 RenderProxyBoxMixin.hitTestChildren (package:flutter/src/rendering/proxy_box.dart:114:19)
E/flutter (11292): #17 RenderBox.hitTest (package:flutter/src/rendering/box.dart:2135:11)
E/flutter (11292): #32 Ren
Restarted application in 10,979ms.
Malformed message
有人可以通过使整个屏幕可滚动来帮助我呈现我的小部件idk
答案 0 :(得分:1)
我有同样的错误。 外层列表使用了SingleChildScrollView,孩子里列表使用容器包起来,设置了高度解决了问题
Container(
height: (group.routes.length * 50)
.toDouble(), // 这里必须告诉flutter高度, 否则不渲染
child: ListView(
padding: EdgeInsets.all(8),
children: group.routes
.map((er) => ListTile(title: Text(er.title)))
.toList(),
),)
答案 1 :(得分:1)
我有同样的错误 & 在我的情况下,原因是 SingleChildScrollView()
我将 ListView.builder 添加到容器中并将容器高度设置为 height:MediaQuery.of(context).size.height,它对我有用。
这是示例:
class ListWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height:MediaQuery.of(context).size.height,
child: ListView.builder(
itemCount: 5,
itemBuilder: (context, index) {
return ListTile(
title: Text('Contact $index'),
);
},
),
);
}
}
现在在 SingleChildScrollView() 中添加 ListWidget
return SingleChildScrollView(
child: Column(
children: [
//.......
ListWidget(),
],
)
);
您可以像这样使用它,或者您可以简单地将它添加到 SingleChildScrollView 中,以防您不想添加任何内容而不是列表。
答案 2 :(得分:0)
我遇到了相同的错误,我的原因是SingleChildScrollView()尝试将其删除
答案 3 :(得分:0)
问题是您将GridView
放在列/行内。异常中的文字很好地说明了错误。
为避免错误,您需要在GridView
内提供一个大小。
我向您建议以下代码,该代码使用Expanded告知高度的水平尺寸(可用的最大值)和SizedBox(可能是容器)的高度:
Column(
children: <Widget>[
Expanded(
child: SizedBox(
height: 200.0,
child: RecentlyViewed()
),
),
new IconButton(
icon: Icon(Icons.remove_circle),
onPressed: () {},
),
],
);
答案 4 :(得分:0)
在 ListView 中将 shrinkWrap 属性设置为 true
shrinkWrap: true