-1

I have a list that comes in the form of future

  Future<List<String>> _future;
  List<String> showList = [];
  String showCode;

  Future<List<String>> getCode() async {
    final show = await SharedPreferences.getInstance();
    setState(() {
      showList = show.getStringList('companyName');
    });
    print('here ${showList.toString()}');
    return showList;
  }

and when I print, my console will output like this

[Friends,Scrubs]

I'm trying to show this list to user by using Futurebuilder but my value is not show. I added it as a column in the container to be centered on the bottom.but only the CircularProgressIndicator() part is visible Any idea?

  ? Container(
                  child: Padding(
                    padding: const EdgeInsets.all(16.0),
                    child: Column(
                      children: [
                        Column(
                          children: [
                            IconButton(
                                icon: Icon(Icons.close),
                                onPressed: () {
                                  Navigator.pushNamed(
                                      context, ShowScreen.routeName);
                                }),
                            Text(
                              'Please Select Show',
                            
                          ],
                        ),
                        FutureBuilder(
                        future: _future,
                        builder: (context,
                            AsyncSnapshot<List<String>> snapshot) {
                          if (snapshot.hasData) {
                            return ListView.builder(
                                itemCount: snapshot.data.length,
                                itemBuilder: (context, index) {
                                  return Card(
                                      elevation: 6.0,
                                      child: Padding(
                                        padding: const EdgeInsets.all(8.0),
                                        child: Row(
                                          crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                          children: <Widget>[
                                            Text(snapshot.data[index]),
                                          ],
                                        ),
                                      ));
                                });
                          }  else{
                            return CircularProgressIndicator();
                          }

                        }),
                      ],
                    ),
                  ),
                )

looks like this, but its not show items

enter image description here

I set my data like this

else{

        _showData = !_showData;
       shows.forEach((element) {
               showCode = element.showName;
               showList.add(element.showName);
                show.setStringList(
              'showName', showList);
                getCode();
                                           
                                            })
kimSoo
  • 283
  • 1
  • 4
  • 10

1 Answers1

0

Set shrinkWrap property of the ListView to true:

I added a demo using your code as an example:

  return ListView.builder(
      itemCount: snapshot.data.length,
      shrinkWrap: true, // new line
      itemBuilder: (context, index) {
        return Card(
            elevation: 6.0,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(snapshot.data[index]),
                ],
              ),
            ));
      },
    );
void
  • 12,787
  • 3
  • 28
  • 42
  • I added but there was no change – kimSoo Sep 08 '20 at 10:54
  • Check the console for any warnings or errors. It worked when I tried the fix I posted. – void Sep 08 '20 at 10:58
  • Does the `progress indicator` show ? Does it stop ? What happens immediately after it stops ? – void Sep 08 '20 at 11:03
  • keeps spinning, does not stop. I added a visual above to understand better – kimSoo Sep 08 '20 at 11:11
  • Can i see the `future` you are passing to the `FutureBuilder` widget ? – void Sep 08 '20 at 11:14
  • Where are you calling the `getCode` method ? You should have something like `_future = getCode()` in your `initState`. – void Sep 08 '20 at 11:26
  • yes when I add it to initState the loading screen disappears and there is a blank space (again no error) – kimSoo Sep 08 '20 at 11:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/221151/discussion-between-void-and-kimsoo). – void Sep 08 '20 at 11:35