无法将 FLUTTER 参数分配给参数类型
FLUTTER Argument cant be assigned to the Parameter type
错误: 参数类型 'User (where User is defined in <dir>\<project>\lib\pages\home.dart)'
cannot be assigned to the parameter type 'User (where User is defined in <dir>\<project>\lib\pages\timeline.dart)'.
代码 : home.dart
Scaffold buildAuthScreen() {
return Scaffold(
key: _scaffoldKey,
body: PageView(
children: <Widget>[
Timeline(currentUser: currentUser),
ActivityFeed(),
Upload(currentUser: currentUser),
Search(),
Profile(profileId: currentUser?.id),
代码 : timeline.dart
class Timeline extends StatefulWidget {
final User currentUser;
Timeline({this.currentUser});
在不同的页面上它工作但在时间轴上我不明白为什么它显示这个错误。
您在两个不同的文件中有两个单独的 class,它们都命名为 User
。尽管它们具有相同的 class 名称,但它们是不同的 class(即使它们具有相同的实现)。
如果它们确实应该分开 class,您应该考虑将它们重命名为不同的名称。如果那不可能,您可以在导入时通过 specifying a library prefix 消除它们的歧义:
import 'timeline.dart' as timeline;
那你可以用timeline.User
来特指timeline.dart
的版本
我运行遇到了同样的问题。为我解决的是遍历每个文件并确保我使用相同类型的本地导入(相对文件列表与包)IE:
import './local/file.dart';
import 'package:local_package/local/file.dart';
我还必须仔细检查所有导入的区分大小写。我通过重命名和改组发现案例与文件系统实际具有的 I.E. 不匹配:
import './local/file.dart'
Filesytem:
.../project/lib/Local/file.dart (Notice the capital L in "Local"
再加上我的主目录中的 .dartServer 的删除,一扫而光,为了更好的衡量,我删除了一个抱怨的文件并重新创建了它,我就像新的一样。
错误: 参数类型 'User (where User is defined in <dir>\<project>\lib\pages\home.dart)'
cannot be assigned to the parameter type 'User (where User is defined in <dir>\<project>\lib\pages\timeline.dart)'.
代码 : home.dart
Scaffold buildAuthScreen() {
return Scaffold(
key: _scaffoldKey,
body: PageView(
children: <Widget>[
Timeline(currentUser: currentUser),
ActivityFeed(),
Upload(currentUser: currentUser),
Search(),
Profile(profileId: currentUser?.id),
代码 : timeline.dart
class Timeline extends StatefulWidget {
final User currentUser;
Timeline({this.currentUser});
在不同的页面上它工作但在时间轴上我不明白为什么它显示这个错误。
您在两个不同的文件中有两个单独的 class,它们都命名为 User
。尽管它们具有相同的 class 名称,但它们是不同的 class(即使它们具有相同的实现)。
如果它们确实应该分开 class,您应该考虑将它们重命名为不同的名称。如果那不可能,您可以在导入时通过 specifying a library prefix 消除它们的歧义:
import 'timeline.dart' as timeline;
那你可以用timeline.User
来特指timeline.dart
的版本
我运行遇到了同样的问题。为我解决的是遍历每个文件并确保我使用相同类型的本地导入(相对文件列表与包)IE:
import './local/file.dart';
import 'package:local_package/local/file.dart';
我还必须仔细检查所有导入的区分大小写。我通过重命名和改组发现案例与文件系统实际具有的 I.E. 不匹配:
import './local/file.dart'
Filesytem:
.../project/lib/Local/file.dart (Notice the capital L in "Local"
再加上我的主目录中的 .dartServer 的删除,一扫而光,为了更好的衡量,我删除了一个抱怨的文件并重新创建了它,我就像新的一样。