无法将FLUTTER参数分配给参数类型 [英] FLUTTER Argument cant be assigned to the Parameter type

查看:88
本文介绍了无法将FLUTTER参数分配给参数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:参数类型'User(其中,用户在< dir> \< project> \lib\pages\home.dart中定义)'不能分配给参数类型'User(其中User在< dir> \< project> \lib\pages\中定义timeline.dart)'。

Error: The argument type 'User (where User is defined in <dir>\<project>\lib\pages\home.dart)' can't be assigned to the parameter type 'User (where User is defined in <dir>\<project>\lib\pages\timeline.dart)'.

代码:home.dart

Code : 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

Code : timeline.dart

class Timeline extends StatefulWidget {
final User currentUser;
Timeline({this.currentUser});

在不同的页面中它可以工作,但是在时间轴上我不解释为什么它显示

in different pages it working but in timeline i don't why its showing this error.

Github链接

推荐答案

您有两个单独的类,分别在两个不同的文件中分别命名为 User 。即使它们具有相同的类名,也可以是不同的类(即使它们具有相同的实现)。

You have two separate classes both named User in two different files. Even though they have the same class name, they are different classes (even if they have identical implementations).

如果它们确实应该是单独的类,则应考虑重命名它们有所不同。如果不可能,则可以通过指定库前缀来消除它们的歧义。 导入时:

If they really should be separate classes, you should consider renaming them to be different. If that's not possible, you can disambiguate them by specifying a library prefix when you import:

import 'timeline.dart' as timeline;

然后您可以使用时间轴。用户具体参考 timeline.dart 的版本。

Then you can use timeline.User to refer specifically to timeline.dart's version.

这篇关于无法将FLUTTER参数分配给参数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆