Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 参数类型';未来<;xxx>';can';不能分配给参数类型';未来者<;xxx>';颤振与振动;飞奔_Flutter_Dart - Fatal编程技术网

Flutter 参数类型';未来<;xxx>';can';不能分配给参数类型';未来者<;xxx>';颤振与振动;飞奔

Flutter 参数类型';未来<;xxx>';can';不能分配给参数类型';未来者<;xxx>';颤振与振动;飞奔,flutter,dart,Flutter,Dart,如果使用字符串作为类型,则此代码有效,但如果使用类则无效 呼叫代码: Future<Card> getCard() { return Future.value(currPack.getCard()); } 当我使用Card类时,我会收到一条警告消息,上面说: 参数类型“Future”无法分配给参数类型“FutureOr” 如果我将返回类型从Card更改为String,并将方法设置为返回字符串,则效果良好。事实证明,在材质设计中有一个名为Card的类:“package:f

如果使用字符串作为类型,则此代码有效,但如果使用类则无效

呼叫代码:

Future<Card> getCard() {
    return Future.value(currPack.getCard());
  }
当我使用Card类时,我会收到一条警告消息,上面说:

参数类型“Future”无法分配给参数类型“FutureOr”


如果我将返回类型从Card更改为String,并将方法设置为返回字符串,则效果良好。

事实证明,在材质设计中有一个名为Card的类:“package:flatter/src/material/Card.dart”

第一位代码是导入material.dart(导入“package:flatter/material.dart”)屏幕的一部分

另一个代码来自一个独立类,该类不导入material.dart,但引用本地卡片类(import'package:flashcards/modules/card.dart';)

总而言之,这个错误是由于引用了两个同名的类而没有区分这两个类造成的。

Future
应该可以分配给
FutureOr
。请张贴一个可复制的例子。您确定没有单独的
类吗?也就是说,
返回Future.value(currPack.getCard())
是多余的,可以只返回currPack.getCard()
  Future<Card> getCard() async {
    return Card("a", "b");
  }
class Card  {
  String question = "";
  String answer = "";

  Card(String question, String answer) {
    this.question = question;
    this.answer = answer;
  }
}