gpt4 book ai didi

flutter - 如何在 flutter 的Listview中显示字符串列表

转载 作者:行者123 更新时间:2023-12-03 03:50:41 25 4
gpt4 key购买 nike

我有字符串列表。我需要在界面中将它们显示为列表。

List<String> spec_list = urlremoved.split(", ");
我只需要向他们展示。但它不起作用。请帮助遇到或找出错误。
我附上了下面的代码
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');

}

最佳答案

仅当您的 speclistlen是空的虽然按照上面的代码,你似乎得到了未绑定(bind)的高度异常。为了避免这种情况,请使用 shrinkWrap: true,里面 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]);
},
)
],
),
);
});
}

关于flutter - 如何在 flutter 的Listview中显示字符串列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63544024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com