Kshitij dhyani
Kshitij dhyani

Reputation: 611

List view builder unable to render anything

I want to create a list view using data fetched from the server , i have achieved fetching successfully but due to some unknown reason i am unable to render anything on to the screen.

      import 'package:flutter/material.dart';

      class Activity extends StatefulWidget {
        Map<String, dynamic> livefeed;

        Activity(this.livefeed);

        @override
        State<StatefulWidget> createState() {
          // TODO: implement createState

          return ActivityState();
        }
      }

      class ActivityState extends State<Activity> {
        @override
        Widget build(BuildContext context) {
          return Stack(
            children: <Widget>[
              Column(
                children: <Widget>[
                  //Text(widget.livefeed.toString()),
                  //Text(widget.livefeed.length.toString()),
                  widget.livefeed != null
                      ? Expanded(
                          child: ListView.builder(
                              itemCount: widget.livefeed.length,
                              itemBuilder: (BuildContext context, int index) {
                                ListTile(
                                  title: Text('HELLO'),
                                );
                              }),
                        )
                      : Text('LOADING'),
                ],
              ),
            ],
          );
        }
      }

I have commented out the part where i print the fetched data on the screen which is being successfully achieved . After that when i use the Listview.Builder to create list tiles based on the same nothing is rendered on the screen. (where i should be getting as many listtiles as the entries in the map)

I do not understand the behavior also there is no error in the console.

Upvotes: 0

Views: 34

Answers (1)

Here you are missing return statement

itemBuilder: (BuildContext context, int index) {
    return ListTile(title: Text('HELLO'),
    );
}),

or simply

itemBuilder: (BuildContext context, int index) => ListTile(title: Text('HELLO'));),

Upvotes: 2

Related Questions