4

I have list of strings.I need to show them in interface as list.

List<String> spec_list = urlremoved.split(", ");

I need to just show them.but it is not working.please help met o findout the error. I have attached the code below

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';



class ItemView extends StatefulWidget {
  final String docID123;

  const ItemView({ this.docID123}) ;

  @override
  _ItemViewState createState() => _ItemViewState();
}
String name123;
class _ItemViewState extends State<ItemView> {
  @override
  //String docuID = Widget.documentid;
  
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Item Data'),
      ),
      body: ListView(
        children: <Widget>[
          Text(widget.docID123),
          getItems(),
          
        ],
      ),
    );
  }
}


Widget getItems(){
    return StreamBuilder(
      //1597917013710
      stream: Firestore.instance.collection('ads').document('1597917013710').snapshots(),
      builder: (context, snapshot){
        if (!snapshot.hasData) {
          //snapshot.data.toString();
          return new Text("Loading");
        }
        DocumentSnapshot dd = snapshot.data; 

        var userDocument = snapshot.data;
        //String myname = dd.data.toString();
        int len = dd.data.length;
        
        String jsonString = dd.data.toString();
        String start = "[";
        String end = "]";
        final startIndex = jsonString.indexOf(start);
        final endIndex = jsonString.indexOf(end, startIndex + start.length);
        String next = jsonString.substring(startIndex + start.length, endIndex);
        String imagelinkRemoved = jsonString.replaceAll(next, "");
        String urlremoved = imagelinkRemoved.replaceAll("urls: [], ", "").replaceAll("{", "").replaceAll("}", "");

        List<String> spec_list = urlremoved.split(", ");
        int speclistlen = spec_list.length;
        
        return Container(
      child: Column(
        children: <Widget>[
          Text(spec_list[0]),
          ListView.builder(
            itemCount: speclistlen,
            itemBuilder: (context,index){
              return Text(spec_list[index]);
            },
          )
        ],
      ),
    );
      }
    );
}


Future getCatagory() async {
      var firestone = Firestore.instance;

      QuerySnapshot alldata = await firestone.collection("catagory_names/Vehicles").getDocuments();
      for(int i=0;i<alldata.documents.length;i++){
                        DocumentSnapshot snap = alldata.documents[i];
                        
                      }

      return  Text('12345');

    }
4
  • You should use return Text(spec_list[index]; in your ListView.builder. Commented Aug 23, 2020 at 6:25
  • I am using return Text(spec_list[index];...but no output Commented Aug 23, 2020 at 6:28
  • That might be because your spec_list is empty. Try printing speclistlen to see if it contains items. Commented Aug 23, 2020 at 6:30
  • it is not empty Commented Aug 23, 2020 at 6:59

1 Answer 1

3

This can only happen if your speclistlen is empty While following above code it seems that you are getting unbound height exception. To avoid that use shrinkWrap: true, inside Listview.Builder

Widget getItems() {
  return StreamBuilder(
      //1597917013710
      stream: Stream.periodic(Duration(seconds: 2)),
      builder: (context, snapshot) {
        String urlremoved = "I, am, jits555";

        List<String> spec_list = urlremoved.split(", ");
        int speclistlen = spec_list.length;

        return Container(
          child: Column(
            children: <Widget>[
              Text(spec_list[0]),
              ListView.builder(
                shrinkWrap: true,
                itemCount: speclistlen,
                itemBuilder: (context, index) {
                  return Text(spec_list[index]);
                },
              )
            ],
          ),
        );
      });
} 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.