ayushman
ayushman

Reputation: 25

Returning ListView.Builder to IndexdedStack

main.dart

.......
final _widgetOptions = [Post(), Cat(), Fav(), Editors()];
..........
@override
Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
    title: Text(widget.title),
  ),
  body: IndexedStack(index: currentIndex, children: _widgetOptions), //so on

post.dart

import 'package:flutter/material.dart';

class Cat extends StatefulWidget {
@override
_CatState createState() => _CatState();
}

class _CatState extends State<Cat> {
 @override
 Widget build(BuildContext context) {
return SingleChildScrollView(
        child: Column(
  children: <Widget>[
    Text("Latest Posts"),
    
    ListView.builder(
      itemBuilder: (context, index) {
        return Text("DEMO DATA");
      },
      itemCount: 2,
    )
  ],
));
}
}

when i try to return a column with having children TEXT and ListView.builder the execution gets stop with error msg " ════════ Exception caught by rendering library ═════════════════════════════════ RenderBox was not laid out: RenderSemanticsGestureHandler#abd36 relayoutBoundary=up10 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': Failed assertion: line 1694 pos 12: 'hasSize'"

Note: if i remove ListView.builder inside from the column or I directly return ListView.builder then no error But i want to show a Text First then List Items

Upvotes: 1

Views: 513

Answers (1)

Wambert Orion
Wambert Orion

Reputation: 406

you can try this to solve your problem.

class Cat extends StatefulWidget {
@override
_CatState createState() => _CatState();
}

class _CatState extends State<Cat> {
 @override
 Widget build(BuildContext context) {
return Column(
  children: <Widget>[
    Text("Latest Posts"),

    Expanded(
      child:ListView.builder(
      itemBuilder: (context, index) {
        return Text("DEMO DATA");
      },
      itemCount: 100,
    )
    )
  ],
);
}
}

Upvotes: 0

Related Questions