Reputation: 1
when I learning flutter's GridView.builder ,I got this question this is my code,
// ignore_for_file: avoid_unnecessary_containers, avoid_print
import 'package:flutter/material.dart';
import './res/listdata.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('你好 Flutter'),
),
body: const MyHomePage()),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
Widget _initGridViewData(context, index) {
return Container(
decoration: BoxDecoration(
border: Border.all(color: const Color.fromRGBO(0, 0, 0, 0.259))),
child: Column(mainAxisSize: MainAxisSize.min, children: [
Image.network(
listData[index]["imageUrl"],
height: 100,
width: 100,
),
const SizedBox(
height: 10,
),
Text(
"${listData[index]["title"]}",
style: const TextStyle(color: Colors.pink),
)
]),
);
}
@override
Widget build(BuildContext context) {
return GridView.builder(
itemCount: listData.length,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
mainAxisExtent: 10,
crossAxisSpacing: 10,
crossAxisCount: 2,
childAspectRatio: 1.0),
itemBuilder: _initGridViewData,
);
}
}
and this is error,
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════ The following assertion was thrown during layout: A RenderFlex overflowed by 122 pixels on the bottom.
The relevant error-causing widget was: Column Column:file:///D:/Code/Flutter/flutterdemo01/lib/main.dart:32:14
To inspect this widget in Flutter DevTools, visit: http://127.0.0.1:9101/#/inspector?uri=http%3A%2F%2F127.0.0.1%3A60467%2F10J_HrK6UIA%3D%2F&inspectorRef=inspector-172
The overflowing RenderFlex has an orientation of Axis.vertical. The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex. Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size. This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView. The specific RenderFlex in question is: RenderFlex#e1c11 OVERFLOWING: creator: Column ← Padding ← DecoratedBox ← Container ← RepaintBoundary ← IndexedSemantics ← _SelectionKeepAlive ← NotificationListener ← KeepAlive ← AutomaticKeepAlive ← KeyedSubtree ← SliverGrid ← ⋯ parentData: offset=Offset(1.0, 1.0) (can use size) constraints: BoxConstraints(w=173.0, h=8.0) size: Size(173.0, 8.0) direction: vertical mainAxisAlignment: start mainAxisSize: min crossAxisAlignment: center verticalDirection: down ◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤ ════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: A RenderFlex overflowed by 122 pixels on the bottom. Another exception was thrown: A RenderFlex overflowed by 122 pixels on the bottom.
I add the images height and width,and try add maxAxisSize,but it still error,thank you for your help
Upvotes: 0
Views: 49
Reputation: 56
I believe the components perhaps need more space than the screen size. Try wrapping your GridView.Build
in a SingleChildScrollView
.
And put the following on the GridView.Build
to make it scrollable:
physics: ScrollPhysics(),
Upvotes: 0