Reputation: 181
I am learning flutter and this code is straight from the teacher. I know that flutter changing all the time and this may be why it is not running. anyways here it is:
class Klimatic extends StatefulWidget {
@override
_KlimaticState createState() => new _KlimaticState();
}
class _KlimaticState extends State<Klimatic> {
String _cityEntered;
Future _goToNextScreen(BuildContext context) async {
Map results = await Navigator
.of(context)
.push(new MaterialPageRoute<dynamic>(builder: (BuildContext context) {
return new ChangeCity();
}));
if ( results != null && results.containsKey('enter')) {
_cityEntered = results['enter'];
// debugPrint("From First screen" + results['enter'].toString());
}
}
Upvotes: 5
Views: 17411
Reputation: 29783
This is because the current Flutter reject the parameter type of dynamic
for MaterialPageRoute
.
You need to change the following code:
Map results = await Navigator
.of(context)
.push(new MaterialPageRoute<dynamic>(builder: (BuildContext context) {
return new ChangeCity();
}));
to
Map results = await Navigator.of(context)
.push(MaterialPageRoute(builder: (BuildContext context) {
return ChangeCity();
})
);
As you can see from the above changes, you don't need the dynamic
keyword. And there is no need for new
keyword anymore because it's optional now.
Upvotes: 3
Reputation: 8614
Without knowledge of the exact API details, it looks like you are expecting a type of Route<Map>
, but you're creating a Route<dynamic>
(or MaterialPageRoute<dynamic>
). I'm assuming you could try:
new MaterialPageRoute<Map>(...)
... instead.
Upvotes: 5