Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter ListViewBuilder Listile Header Text

I have a set of tabs, within one of the tabs i have a futurebuilder that has a listviewBuilder and ListTile. How do I add a header container/Sizedbox above the listtiles.
I have tried adding columns, SingleChildScrollView, CustomScrollView with slivers but keeps getting errors

Widget localAttractionsTab() {
    return FutureBuilder(
        future: localAttractions(widget.locationId),
        builder: (BuildContext context, AsyncSnapshot<Amenities> snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return const Center(child: CircularProgressIndicator());
          } else if (snapshot.error != null) {
            return const Center(child: Text('an error occured!'));
          } else {
            return
             ListView.builder(
                itemCount: snapshot.data!.attraction.length,
                itemBuilder: (context, index) {
                  return ListTile(
                    title: Text(snapshot.data!.attraction[index].attractionname),
                    //subtitle: Text(el.),
                    onTap: () {
                      //Got To Amenity Details Page
                      Navigator.of(context).push(
                        MaterialPageRoute(
                          builder: (context) => AttractionDetailsScreen(
                              attractionID: snapshot.data!.attraction[index].id
                             ),
                        ),
                      );
                    },
                  );
                }
            );
          }
        });
  }


>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Widget localAttractionsTab() {
    return FutureBuilder(
        future: localAttractions(widget.locationId),
        builder: (BuildContext context, AsyncSnapshot<Amenities> snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return const Center(child: CircularProgressIndicator());
          } else if (snapshot.error != null) {
            return const Center(child: Text('an error occured!'));
          } else {
            return
             ListView.builder(
                itemCount: snapshot.data!.attraction.length + 1,
                itemBuilder: (context, index) {
                  if(index == 0){
                    return Container(); // add whatever you want here
                  }
                  else{
                    return ListTile(
                    title: Text(snapshot.data!.attraction[index].attractionname),
                    //subtitle: Text(el.),
                    onTap: () {
                      //Got To Amenity Details Page
                      Navigator.of(context).push(
                        MaterialPageRoute(
                          builder: (context) => AttractionDetailsScreen(
                              attractionID: snapshot.data!.attraction[index].id
                             ),
                        ),
                      );
                    },
                  );
                  }
                  
                }
            );
          }
        });
  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading