Trying to show ListView.builder of List inside Container

Here is the full code you yo can see the error is to long dont know what to do
i want to render the data from list with a ListView

import "package:flutter/material.dart";

void main() => runApp(MasterFul());

class MasterFul extends StatefulWidget{
  @override
  Master createState() => Master();
}

class Master extends State<MasterFul>{
  int number = 0;
  final name = TextEditingController();
  final  List  lista = [{"id": 1, "name": "test"}, {"id": 2, "name": "test2"}];
  @override
  Widget build(BuildContext context){
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("Flutter")
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              Container(
                child: Text(name.text),
              ),
              Container(
                width: 300.0,
                child: TextField(
                  controller: name,
                  decoration: InputDecoration(
                    hintText: 'Name',
                    prefixIcon: Icon(Icons.nature),
                  ),
                )
              ),
             Container(
              child: ListView.builder(
                itemCount: lista.length,
                itemBuilder: (BuildContext ctxt, int index) {
                  return Container(
                    child: Text(lista[index]["name"].toString()),
                  );
                }
            ),
             ),
      
              Container(
                child: FlatButton(
                  onPressed: (){
                    lista.add({"id": 1, "name": "test"});
                    print(lista);
                  },
                  child: Text("Increment")
                )
              )
            ]
          )
        )
      )
    );
  }
}

Please give a height to the parent Container of List and also set the property shrinkWrap to true.

Glad to help, do let us know if it resolves your query :slight_smile:

3 Likes

It works thanks a lot ;P.

2 Likes

It’s really sad to be obliged to fixe a height to my list when i am supposed to do things dynamically

That’s true. It bugs me as well.