我有一个基于列表构建 UI 的 futurebuilder,它完成了这项工作,但是由于每当我导航时一次又一次地构建 UI,我会得到重复的内容。我的问题是,Dart 中是否有一种固有的方法可以从列表中删除重复项?我已经尝试过这个StackOverflow 问题,但它不起作用。
这是我的定制模型:
class HomeList {
Widget navigateScreen;
String imagePath;
PatientInfo patientInfo;
HomeList({
this.navigateScreen,
this.imagePath = '',
this.patientInfo,
});
static List<HomeList> homeList = [];
}
Run Code Online (Sandbox Code Playgroud)
这是我从 cloud_firestore 获取数据的 futureBuilder 函数:
_getPatients() async {
if (didLoadpatients == 0) {
print('this is didloadpatients at start of func $didLoadpatients');
var document = await db
.collection('users')
.document(mUser.uid)
.collection('patients');
document.getDocuments().then((QuerySnapshot query) async {
query.documents.forEach((f) {
uids.add(f.data['uID']);
});
didLoadpatients++;
print('this is didloadpatients at end of func $didLoadpatients');
for (var …Run Code Online (Sandbox Code Playgroud) 我正在为我的应用程序创建一个通知中心,它包含一些标题和正文的长字符串,它总是导致溢出,我尝试使用扩展小部件,以及以下堆栈溢出问题:问题 1 ,问题 2但我不能将它应用到我的代码中,现在它是这样的:
我从我的 firebase cloud firestore 获取文本,并使用列表视图输出文本。
该标题文字是这样的:“艾伦Indefenzo已取消同意您访问他/她的数据”
的正文是这样的:“他/她已经删除了所有的访问,您将不再能够查看/修改他的数据,再次访问要求用户再次向您提供他/她的特殊代码。”
这是我的代码:
Container(
color: Colors.white,
child: StreamBuilder(
stream: db
.collection('users')
.document(userData.userID)
.collection('notifications')
.snapshots(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
if (snapshot.data.documents.length != 0) {
return ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (BuildContext context, int index) {
return Container(
child: Row(
children: <Widget>[
Container(
height: 150,
width: 100,
child: Image(
image: NetworkImage(
snapshot.data.documents[index]['dpURL']), fit: BoxFit.contain,
),
), …Run Code Online (Sandbox Code Playgroud)