I'm trying to get description text from Firecloud database and use them in 3 differnt widgets, add those widget to a list and then pass that list in a ListView
.
I executed the following code for this purpose inside StreamBuilder
:
StreamBuilder(
stream: FirebaseFirestore.instance.collection('humansOfLpc').snapshots(),
builder: (BuildContext context,snapshot){
if(!snapshot.hasData){
return Center(
child: Text('Loading...'),
);
}
print('outside title and desc widget');
List<TitleAndDescription> titleAndDescriptions=[
];
snapshot.data.docs.map((document){
final about = document.data()["about"];
final aftercampusProgress =document.data()["afterCampusPlacement"];
final incampusPlacement = document.data()["incampusProgress"];
print('inside snapshots');
print(about);
final aboutDesc = TitleAndDescription(
title: 'About',
description: about,
);
final incampusProgressDesc = TitleAndDescription(
title: 'In-Campus Progress',
description: incampusProgress,
);
final afterCampusPlacementDesc=TitleAndDescription(
title: 'After Campus Placements',
description: afterCampusPlacement,
);
titleAndDescriptions.add(aboutDesc);
titleAndDescriptions.add(incampusProgressDesc);
titleAndDescriptions.add(afterCampusPlacementDesc);
});
return Expanded(
child: ListView(
children: titleAndDescriptions,
),
);
},
),
The main problem here I am facing is that its not reading the following code:
snapshot.data.docs.map((document){
final about = document.data()["about"];
final aftercampusProgress =document.data()["afterCampusPlacement"];
final incampusPlacement = document.data()["incampusProgress"];
print('inside snapshots');
print(about);
final aboutDesc = TitleAndDescription(
title: 'About',
description: about,
);
final incampusProgressDesc = TitleAndDescription(
title: 'In-Campus Progress',
description: incampusProgress,
);
final afterCampusPlacementDesc=TitleAndDescription(
title: 'After Campus Placements',
description: afterCampusPlacement,
);
titleAndDescriptions.add(aboutDesc);
titleAndDescriptions.add(incampusProgressDesc);
titleAndDescriptions.add(afterCampusPlacementDesc);
});
I can say this since the console is printing 'outside title and desc widget'
but not printing 'inside snapshots'
.
Because of this my titleAndDescriptions
list is empty and I am not getting the 3 widgets as well as data on my UI. Pls tell what am I doing wrong and what alternative do I have instead ?
Thanks in advance.