Reputation:
I am facing this Exception :
FlutterError (RenderViewport does not support returning intrinsic dimensions. Calculating the intrinsic dimensions would require instantiating every child of the viewport, which defeats the point of viewports being lazy. If you are merely trying to shrink-wrap the viewport in the main axis direction, consider a RenderShrinkWrappingViewport render object (ShrinkWrappingViewport widget), which achieves that effect without implementing the intrinsic dimension API.)
When i add ProductsWidget
the Exception occurs.
the code of Products Widget is:
class ProductsWidget extends GetResponsiveView<HomeTabController> {
@override
Widget build(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
itemCount: 3,
// padding: EdgeInsets.symmetric(vertical: 20),
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) => Column(
children: [
Row()])}}
the calling code is:
body: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraints.maxHeight,
),
child: IntrinsicHeight(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
// flex: 1,
child: HomeAppBar()),
// listView
// i made shrinkWrap=true
// neverScroll
Flexible(fit: FlexFit.tight, child: ProductsWidget()),
],
),
),
),
);
}),
Upvotes: 10
Views: 25480
Reputation: 1062
The issue happens because of using the Listview inside the Renderviewport. To solve it you can wrap your Listview in a SizedBox and give it a height and width of double.maxFinite (or whatever is needed)
My code:
SliverFillRemaining(
hasScrollBody: false,
child: SafeArea(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: SizedBox(
height: double.maxFinite,
width: double.maxFinite,
child: ListView.separated(
....
)
Upvotes: 1
Reputation: 47
Convert ListView to List.generate and it will solve the problem.
Upvotes: -1
Reputation: 11
I solved my problem by wrapping with SizedBox and give potential height and width. Then I wrapped the SizedBox with Column.
Upvotes: 1
Reputation: 6264
Replace SingleChildScrollView
with CustomScrollView
like this:
return Scaffold(
appBar: AppBar(
title: Text('Expanded Scrollable'),
),
body: CustomScrollView(
physics: AlwaysScrollableScrollPhysics(),
slivers: [
SliverFillRemaining(
fillOverscroll: true,
child: Column(
children: <Widget>[
Text('Hello ... '),
Divider(
height: 2,
),
Expanded(
child: Container(color: Colors.red,), // replace this Container with your listview
)
],
),
)
],
),
);
Upvotes: 1
Reputation: 1533
That is because ListView builds each child lazily. You can use a Column wrapped in a SingleChildScrollView instead of the ListView.
Upvotes: 8
Reputation: 577
Try wrapping your ProductsWidget in a SizedBox and give it a width (width: double.maxFinite,) and potentially height.
I had a similar issue and I found the following post helpful: flutter listview with radio not showing in alertDialog
Upvotes: 12