I need to update a document with nested arrays in Firestore with Flutter.
So I need to get the full document into a Map, reorder the maps in the \"sections\" array,
Needed to simplify for purpose of example
class ItemsList extends StatelessWidget {
@override
Widget build(BuildContext context) {
// get the course document using a stream
Stream courseDocStream = Firestore.instance
.collection('Test')
.document('4b1Pzw9MEGVxtnAO8g4w')
.snapshots();
return StreamBuilder(
stream: courseDocStream,
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.active) {
// get course document
var courseDocument = snapshot.data.data;
// get sections from the document
var sections = courseDocument['sections'];
// build list using names from sections
return ListView.builder(
itemCount: sections != null ? sections.length : 0,
itemBuilder: (_, int index) {
print(sections[index]['name']);
return ListTile(title: Text(sections[index]['name']));
},
);
} else {
return Container();
}
});
}
}
The Results