Pls help me out in this, In below code I am trying to call a list of hobbies which is stored in firestore but getting error which is mentioned below and neither I am able to fetch values from firestore as I tried to print it. This is a screen shot from firestore:-
Getting this error:-
Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'Future<dynamic>'
This is the screen:-
class EditInfo extends StatefulWidget{
final User currentUser;
EditInfo({this.currentUser});
@override
EditInfoState createState () => EditInfoState();
}
class EditInfoState extends State<EditInfo>
with SingleTickerProviderStateMixin{
String currentuser;
Future myInterest;
void initState() {
super.initState();
getalldata()
}
getalldata() async {
Future<CreateAccountData> getUser() async {
final User user = auth.currentUser;
return _reference.doc(user.uid).get().then((m) => CreateAccountData.fromDocument(m));
}
getUser().then((value)async{
accountData= value;
DocumentSnapshot doc = await usercollection.doc(auth.currentUser.uid).get();
myInterest = doc.data()['hobbies']; //Error takes me here
});
}
This is where I want to display it in Grid view:-
child: FutureBuilder(
future: myInterest,
builder: (BuildContext context,AsyncSnapshot snapshot){
if(!snapshot.hasData){
return Center(
child: CircularProgressIndicator(),
);
} if(snapshot.data.docs.isEmpty){
return Align(
alignment: FractionalOffset.centerLeft,
child: Text("Add what you love to do.....",textAlign: TextAlign.left,style: TextStyle(fontSize: 17),),
);
}return GridView.builder(
physics: BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: snapshot.data.docs.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, childAspectRatio: 5, crossAxisSpacing: 5,),
itemBuilder: (BuildContext context, int index){
// DocumentSnapshot interestList = snapshot.data.docs[index]['hobbies'];
return Padding(
padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
child: Text(snapshot.data.documents[index]['hobbies']),
);
}
);
},
),