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

ListView showing only 1 card widget but causes blank space below

i’m trying to display only 1 card widget inside a listView.builder, the card is displayed but shows extra space that I couldn’t find a way to remove.

There are actually 2 separated listViews, one should contain a single card and another that holds a list of cards.

here’s my code:

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: Text(
        'Fiche du patient',
        style: TextStyle(color: Colors.black),
      )),
      body: Column(
        children: <Widget>[
          Expanded(
            child: ListView.builder(
                itemCount: 1,
                itemBuilder: (BuildContext context, int index) {
                  return Card(
                    color: Colors.white,
                    elevation: 2.0,
                    margin: EdgeInsets.all(10),
                    child: ListTile(
                      contentPadding: EdgeInsets.only(right: 30, left: 36),
                      title: Text('${widget.patient['nomComplet']}'),
                      subtitle: Text('Médecin: ${widget.patient['medecin']}'),
                      trailing: Text('CH: 107'),
                      leading: Icon(Icons.person),
                    ),
                  );
                }),
          ),
          Expanded(
            child: ListView.builder(
              itemCount: docsMesures.length,
              itemBuilder: (BuildContext context, int index) {
                return Card(
                    margin: EdgeInsets.all(10),
                    child: ListTile(
                      trailing: IconButton(
                        icon: Icon(Icons.edit),
                        onPressed: () {
                          Fluttertoast.showToast(
                              msg: 'Traitement de la demande');
                        },
                      ),
                      contentPadding: EdgeInsets.only(right: 30, left: 36),
                      title: Text(
                          'Demandée par: ${docsMesures[index]['affectePar']}'),
                      subtitle: Text(
                          'Date limite: ${DateFormat('dd-MM-yyyy hh:mm a').format(docsMesures[index]['datePrise'].toDate())}'),
                    ));
              },
            ),
          )
        ],
      ),
    );
  }
}

And here is the result as displayed:

enter image description here

Thanks in advance!

>Solution :

That’s because you are using Expanded in a column of two ListViews, this would result in each one of them having half of the height.

removing the Expanded from the first ListView and adding shrinkWrap:true to it would resolve the problem.

so this code for example:

Column(
        children: <Widget>[

          ListView.builder(
                itemCount: 1,
             shrinkWrap: true,

                itemBuilder: (BuildContext context, int index) {
                  return Card(
                    color: Colors.white,
                    elevation: 2.0,
                    margin: EdgeInsets.all(10),
                    child: ListTile(
                      contentPadding: EdgeInsets.only(right: 30, left: 36),
                      title: Text('asdf'),
                      subtitle: Text('Médecin: '),
                      trailing: Text('CH: 107'),
                      leading: Icon(Icons.person),
                    ),
                  );
                }),
     
          Expanded(
            child: ListView.builder(
              itemCount: 11,
              itemBuilder: (BuildContext context, int index) {
                return Card(
                    margin: EdgeInsets.all(10),
                    child: ListTile(
                      trailing: IconButton(
                        icon: Icon(Icons.edit),
                        onPressed: () {
                    
                        },
                      ),
                      contentPadding: EdgeInsets.only(right: 30, left: 36),
                      title: Text(
                          'Demandée par:'),
                  
                    ));
              },
            ),
          )
        ],
      );

would give you something like this:

enter image description here

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