作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有字符串列表。我需要在界面中将它们显示为列表。
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/
我是一名优秀的程序员,十分优秀!