Im having problem reading arrays from Firestore, strings can be readable within future builder as below,
How ever when its time to read array field in very same document and insert in a list is just not working , actually Im not able to read the array with get method. tried [] method but always receving getting null error, List experiences = snapshot.data.get('experiences') is not working for arrays,
Is there a different method for reading arrays from firebase ? I also need to read that array put in a list and use it to list the selected data from each index to a listview as usually we do locally with lists.
Here is the error message:
======== Exception caught by widgets library ======================================================= The following NoSuchMethodError was thrown building FutureBuilder(dirty, state: _FutureBuilderState#395a0): The method 'get' was called on null. Receiver: null Tried calling: get("experiences")
The relevant error-causing widget was: FutureBuilder file:///xxxxxxxx/lib/regformSummary.dart:185:45 When the exception was thrown, this was the stack: #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5) #1 _RegFormSummaryState.build. (package:xxxxxx/regformSummary.dart:186:94) #2 _FutureBuilderState.build (package:flutter/src/widgets/async.dart:773:55) #3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4612:27) #4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4495:15) ...
here is working code for reading strings
//under main widget builder
DocumentReference resumedata =_firestore.collection('users').doc(widget.userID).collection('resume').doc('info');
DocumentReference userdata = _firestore.collection('users').doc(widget.userID).collection('resume').doc('personalinfo');
//
.....,
FutureBuilder(future:userdata.get(),builder: (BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if(snapshot.connectionState == ConnectionState.done){
String profilepic = snapshot.data.get('profilepic');
String name = snapshot.data.get('name');
String sname = snapshot.data.get('sname');
return Column(
children: [
Padding(
padding: EdgeInsets.symmetric(vertical: 10),
child: CircleAvatar(
minRadius: 40,
maxRadius: 80,
backgroundImage: NetworkImage('$profilepic'),
),
),//avatar
Padding(
padding: EdgeInsets.symmetric(horizontal: 10,vertical:3),
child: Text(
name,
style: GoogleFonts.openSans(textStyle: TextStyle(color: Colors.black54,fontSize: 24,fontWeight: FontWeight.bold)),
),
),//name
Padding(
padding: EdgeInsets.symmetric(horizontal: 10,vertical:3),
child: Text(
sname,
style: GoogleFonts.openSans(textStyle: TextStyle(color: Colors.black54,fontSize: 24,fontWeight: FontWeight.bold)),
),
),//sname
],
);
}
return SizedBox();
}),
Here is the failing code
DefaultTabController(
length:8,
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
children: [
TabBar(
isScrollable: true,
indicatorWeight: 4.0,
indicatorColor:Colors.black38,
unselectedLabelColor: Colors.black38,
tabs: <Widget>[
Tab(
child:Text('Tecrübeler',style: TextStyle( color:
colorVal
)),
),
Tab(
child: Text('Eğitim',style: TextStyle( color: colorVal
)),
),
Tab(
child: Text('Yabancı Dil',style: TextStyle( color: colorVal)),
),
Tab(
child: Text('Sertifikalar',style: TextStyle( color: colorVal)),
),
Tab(
child: Text('Referanslar',style: TextStyle( color:colorVal)),
),
Tab(
child: Text('İlgilendiği Pozisyonlar',style: TextStyle( color: colorVal)),
),
Tab(
child: Text('CV dosyası ve Önyazı Dosyası',style: TextStyle( color: colorVal)),
),
Tab(
child: Text('İletişim Bilgileri',style: TextStyle( color: colorVal)),
),
],
),
SizedBox(
height:MediaQuery.of(context).size.height,
child: TabBarView(
children: <Widget>[
FutureBuilder(future:resumedata.get(),builder: (BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot){
List experiences = List.from(snapshot.data.get('experiences'));
if (snapshot.connectionState == ConnectionState.done){
ListView.builder(
itemCount: experiences.length,
itemBuilder: (context,index){
return Padding(
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
child: Container(
decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(20.0)), color: Colors.white, boxShadow: [
BoxShadow(color: Colors.black.withAlpha(100), blurRadius: 5.0),
]),
child: ListTile(
isThreeLine: true,
title: Text('${experiences[index]['position']}'),
subtitle: Text('${experiences[index]['company']} - ${experiences[index]['duration']}'),
),
),
);
});
.....and goes on
and here is the data tree in Firestore