Home > database >  The ListView.builder not working?If i use text instead then it's working properly
The ListView.builder not working?If i use text instead then it's working properly

Time:07-26

The listview isn't working, but if I print using text it's working properly.I can't figure out whats wrong.

(playList.isEmpty || playList == null)
                ? Text(
                    'Empty',
                    style: TextStyle(fontSize: 20, color: Colors.white),
                  )
                : ListView.builder(
                    itemCount: playList.length,
                    itemBuilder: (BuildContext context, int index) {
                      return ListTile(
                        title: Text(
                          'a',
                          style: TextStyle(fontSize: 20, color: Colors.white),
                        ),
                      );
                    },
                  ),

Working

(playList.isEmpty || playList == null)
                ? Text(
                    'Empty',
                    style: TextStyle(fontSize: 20, color: Colors.white),
                  )
                : Text(
                    playList[0].amount.toString(),
                    style: TextStyle(fontSize: 20, color: Colors.white),
                  )

Class Play

class Play {
  String? amount;
  String? feeText;

  Play(this.amount, this.feeText);
}

CodePudding user response:

You haven't used the any list property in your ListTile, So change

              return ListTile(
                title: Text(
                  'a',
                  style: TextStyle(fontSize: 20, color: Colors.white),
                ),
              );

to

              return ListTile(
                title: Text(
                  playList[index].amount.toString(),
                  style: TextStyle(fontSize: 20, color: Colors.white),
                ),
              );

CodePudding user response:

If the ListView inside column, use Expaneded instead of shrinkwrap

body: Column(
  children: [
    Expanded(
      child: ListView.builder(

If you are putting a ListView inside another ListView, You can just use Column while the parent widget will handle the scrolling event.

return Scaffold(
  body: Column(
    children: [
      Expanded(
        child: ListView.builder(
          itemCount: 3,
          itemBuilder: (context, index) {
            return Column(
              children: playList
                  .map((e) => ListTile(
                        title: Text("text"),
                      ))
                  .toList(),
            );
          },
        ),
      ),
    ],
  ),
);
  • Related