Reputation: 282
I just find out that this part of code is not working any more after updating flutter. I do not understand what is the problem. It was working well before. If you can help me to fix this your help will be appreciated. Many thanks.
the complete error message is
"Couldn't infer type parameter 'T'.
Tried to infer 'dynamic' for 'T' which doesn't work: Parameter 'onChanged' declared as 'void Function(T?)?' but argument is 'void Function(Object?)'. The type 'dynamic' was inferred from: Parameter 'items' declared as 'List<DropdownMenuItem>?' but argument is 'List<DropdownMenuItem>'. Parameter 'value' declared as 'T?' but argument is 'dynamic'.
Consider passing explicit type argument(s) to the generic.
"
Padding(
padding: const EdgeInsets.all(8.0),
child: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('Users')
.doc(FirebaseAuth.instance.currentUser!.uid)
.collection('area_of_Focus')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData)
const Text("Loading.....");
else {
List<DropdownMenuItem> projectItems = [];
for (int i = 0; i < snapshot.data!.docs.length; i++) {
DocumentSnapshot snap = snapshot.data!.docs[i];
projectItems.add(
DropdownMenuItem(
child: Text(
(snap['area_of_Focus_Name']),
style: TextStyle(color: Colors.black),
),
value: (snap['area_of_Focus_Name']),
),
);}
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
DropdownButton( //this is where I am having this error
items: projectItems,
onChanged:
(myFocus) {
setState(() {
selectedFocus = myFocus;
_valueAreaOfFocusSaved = myFocus;
// taskNewValue ['area_of_Focus_Name'] = myFocus ;
});
},
value: selectedFocus,
isExpanded: false,
hint: SizedBox(
width: 315.0,
height: 40.0,
child: Text(
projectName,
style: TextStyle(color: Colors.black),
),
),
),
],
);
}
return Container(
height: 0,width: 0,
);
}
),
),
Upvotes: 0
Views: 399
Reputation: 282
I have find a solution which remove the error message
Padding(
padding: const EdgeInsets.all(8.0),
child: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('Users')
.doc(FirebaseAuth.instance.currentUser!.uid)
.collection('area_of_Focus')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData)
const Text("Loading.....");
else {
List<DropdownMenuItem> projectItems = [];
for (int i = 0; i < snapshot.data!.docs.length; i++) {
DocumentSnapshot snap = snapshot.data!.docs[i];
projectItems.add(
DropdownMenuItem(
child: Text(
(snap['area_of_Focus_Name']),
style: TextStyle(color: Colors.black),
),
value: (snap['area_of_Focus_Name']),
),
);}
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
DropdownButton<dynamic> (
items: projectItems,
onChanged:
(myFocus) {
setState(() {
selectedFocus = myFocus;
_valueAreaOfFocusSaved = myFocus;
// taskNewValue ['area_of_Focus_Name'] = myFocus ;
});
},
value: selectedFocus,
isExpanded: false,
hint: SizedBox(
width: 315.0,
height: 40.0,
child: Text(
projectName,
style: TextStyle(color: Colors.black),
),
),
),
],
);
}
return Container(
height: 0,width: 0,
);
}
),
),
Upvotes: 2