[英]Left Hand Side , Right Hand Side Compiler Errors in Dart / Flutter List
I'm having a terrible time getting this program to run. 我有一个糟糕的时间让这个程序运行。 I keep getting compiler troubles when I run the code.
我运行代码时不断遇到编译器问题。 See specifics below.
请参阅下面的细节。 Anybody understand what's going on here?
谁知道这里发生了什么?
My code extract from file TapScreenToo.dart
: 我的代码从文件
TapScreenToo.dart
提取:
import 'profiles.dart';
import 'package:flutter/material.dart';
import 'cards.dart';
class PageTapScreen extends StatefulWidget {
final List<Profile> profileList;
Key key;
PageTapScreen({
this.key,
this.profileList,
}) : super(key: key); // constructor
@override
_PageTapScreenState createState() => new _PageTapScreenState();
}
The profile class in file profiles.dart
(no import statement there): 文件
profiles.dart
的配置文件类(没有import语句):
class Profile {
final String ttaKey;
final String imageUrl;
final String displayName;
Profile({
this.ttaKey,
this.imageUrl,
this.displayName,
});
}
my profile list from file demoProfiles.dart
: 我的文件
demoProfiles.dart
个人资料列表:
import 'profiles.dart';
final List<Profile> demoProfiles = [
new Profile(
ttaKey: "0",
imageUrl: 'http://localhost:8080/photo_0.jpg',
displayName: 'abc',
),
new Profile(
ttaKey: "1",
imageUrl: 'http:// ... etc
),
]
And all of this gets called in main.dart
所有这些都在
main.dart
中main.dart
import 'package:flutter/material.dart';
import 'tapScreenToo.dart';
import 'demoProfiles.dart';
class _MyHomePageState extends State<MyHomePage> {
final Key keyOne = PageStorageKey('pageOne');
...
@override
void initState() {
tapScreen = PageTapScreen(
key: keyOne,
profileList: demoProfiles, <--- error points here
);
I'm getting a compiler message at the time of initiation: 我在启动时收到编译器消息:
compiler message: lib/main.dart:68:20: Error: A value of type 'dart.core::List<#lib1::Profile>' can't be assigned to a variable of type 'dart.core::List<#lib2::Profile>'.
compiler message: Try changing the type of the left hand side, or casting the right hand side to 'dart.core::List<#lib2::Profile>'.
compiler message: profileList: demoProfiles,`
I've tried to cast (List <Profile>)
but that seems to be a fail, or I'm just doing it wrong. 我试图施放
(List <Profile>)
但这似乎是失败,或者我只是做错了。
Note: when I remark out the error line, and debug step to the failure location, I can see that the values for both keyOne
and demoProfiles
are exactly as expected. 注意:当我注释出错误行,并调试步骤到失败位置时,我可以看到
keyOne
和demoProfiles
的值完全符合预期。 Note, these code snippets are located in different files, linked via import
commands. 请注意,这些代码段位于不同的文件中,通过
import
命令链接。
As I look at the rest of the code, I can see where import 'profiles.dart'
gets called multiple times. 当我查看其余代码时,我可以看到
import 'profiles.dart'
被多次调用的位置。
I don't understand the error message. 我不明白错误信息。 I've also studied this posting with a similar error, but I'm just not seeing what's going on with this code, nor how to fix it.
我也用类似的错误研究了这个帖子,但我只是没有看到这个代码发生了什么,也没有看到如何修复它。
You need to change the imports in the main.dart
: 您需要更改
main.dart
中的main.dart
:
import 'tapScreenToo.dart';
import 'demoProfiles.dart';
Since the main.dart
can only have packages:
imports which are called absolute imports. 由于
main.dart
只能有packages:
导入称为绝对导入。
Therefore change the imports to: 因此将导入更改为:
import package:mypackage/path/tapScreenToo.dart
import package:mypackage/path/demoProfiles.dart
Check this: 检查一下:
Error: A value of type 'List<#lib1::Data>' can't be assigned to a variable of type 'List<#lib2::Data> 错误:无法将类型为“List <#lib1 :: Data>”的值分配给“List <#lib2 :: Data>”类型的变量
https://github.com/dart-lang/sdk/issues/33076 https://github.com/dart-lang/sdk/issues/33076
https://www.dartlang.org/tools/pub/get-started#importing-libraries-from-packages https://www.dartlang.org/tools/pub/get-started#importing-libraries-from-packages
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.