我在我的Flutter应用程序中使用GridView来显示图像及其标题.请检查以下代码.
import 'package:Flutter/material.dart';
import '../common_ui/search_bar.dart';
class PurchaseProductsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Todo: implement build
return PurchaseProductsUI();
}
}
class PurchaseProductsUI extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// Todo: implement createState
return _PurchaseProductUIState();
}
}
class _PurchaseProductUIState extends State<PurchaseProductsUI> {
@override
Widget build(BuildContext context) {
// Todo: implement build
return ListView(
children: <Widget>[
Container(
margin: EdgeInsets.all(20),
child: SearchBar(),
),
Container(
margin: EdgeInsets.all(20),
child: GridView.builder(
physics: ScrollPhysics(), // to disable GridView's scrolling
shrinkWrap: true,
itemCount: 20,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2),
itemBuilder: (BuildContext context, int index) {
return Container(
padding: EdgeInsets.all(5), child: _buildImageBoxes());
})),
],
);
}
Widget _buildImageBoxes() {
return
Column(
children: <Widget>[
Container(
child: Image.network("https://picsum.photos/200/300/?random"),
),
Container(
padding: EdgeInsets.all(10),
child: Text("Text"), )
],
);
}
}
I/Flutter ( 2743): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/Flutter ( 2743): The following message was thrown during layout:
I/Flutter ( 2743): A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): The overflowing RenderFlex has an orientation of Axis.vertical.
I/Flutter ( 2743): The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
I/Flutter ( 2743): black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
I/Flutter ( 2743): Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
I/Flutter ( 2743): RenderFlex to fit within the available space instead of being sized to their natural size.
I/Flutter ( 2743): This is considered an error condition because it indicates that there is content that cannot be
I/Flutter ( 2743): seen. If the content is legitimately bigger than the available space, consider clipping it with a
I/Flutter ( 2743): ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
I/Flutter ( 2743): like a ListView.
I/Flutter ( 2743): The specific RenderFlex in question is:
I/Flutter ( 2743): RenderFlex#4a1bb OVERFLOWING
I/Flutter ( 2743): creator: Column ← Padding ← Container ← RepaintBoundary-[<14>] ← IndexedSemantics ←
I/Flutter ( 2743): NotificationListener<KeepAliveNotification> ← KeepAlive ← AutomaticKeepAlive ← SliverGrid ←
I/Flutter ( 2743): MediaQuery ← SliverPadding ← ShrinkWrappingViewport ← ⋯
I/Flutter ( 2743): parentData: offset=Offset(5.0, 5.0) (can use size)
I/Flutter ( 2743): constraints: BoxConstraints(w=150.0, h=150.0)
I/Flutter ( 2743): size: Size(150.0, 150.0)
I/Flutter ( 2743): direction: vertical
I/Flutter ( 2743): mainAxisAlignment: start
I/Flutter ( 2743): mainAxisSize: max
I/Flutter ( 2743): crossAxisAlignment: center
I/Flutter ( 2743): verticalDirection: down
I/Flutter ( 2743): ◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
I/Flutter ( 2743): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
I/Flutter ( 2743): Another exception was thrown: A RenderFlex overflowed by 111 pixels on the bottom.
Reloaded 0 of 446 libraries in 1,179ms.
以下是用户界面
我怎么解决这个问题?
解决方法:
尝试在_buildImageBoxes()函数中使用Expanded而不是Container
Widget _buildImageBoxes() {
return Column(
children: <Widget>[
Expanded(
child: Image.network("https://picsum.photos/500/500/?random"),
),
Container(
padding: EdgeInsets.all(10),
child: Text("Text"),
)
],
);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。