flutter - 错误 : The argument type 'MaterialPageRoute' can't be assigned to the parameter type 'Route<Map>'

标签 flutter dart

我正在学习 flutter,这段代码直接来自老师。我知道 flutter 一直在变化,这可能就是它没有运行的原因。不管怎样,它是:

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());


    }
  }

最佳答案

在不了解确切的 API 详细信息的情况下,看起来您期待的是一种类型 Route<Map> , 但你正在创建一个 Route<dynamic> (或 MaterialPageRoute<dynamic> )。我假设您可以尝试:

new MaterialPageRoute<Map>(...)

... 相反。

关于flutter - 错误 : The argument type 'MaterialPageRoute' can't be assigned to the parameter type 'Route<Map>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49903420/

相关文章:

dart - 重装 Controller

dart - Flutter:如何制作随机颜色生成器背景

datetime - 在Flutter获得凌晨0点的简单方法是什么?

flutter - 如何在提交时将文本字段更改为另一个小部件?

firebase - 如何使用 Flutter 执行 Firebase 可变事务数据?

android - 如何在flutter中打开android平台上的添加联系人页面?

flutter - 在 Flutter 中画一个圆形菜单

flutter - PopupMenuButton使用不同的屏幕

dart - 正确使用 Dart 变压器

flutter - 运行时 flutter “Lost connection to device”