sách gpt4 ăn đã đi

Mã phi tiêu hoạt động khác trong ứng dụng Flutter của tôi. danh sách<动态>' không phải là một kiểu con của kiểu ' Phân loại< bản đồ <字符串,动态>>

In lại 作者:IT王子 更新时间:2023-10-29 07:00:53 25 4
mua khóa gpt4 giày nike

当我在“Dart”主程序中运行它时,一切正常,并且我得到了一个与会者列表。但是,当我在我的 Flutter 应用程序中调用它时,出现错误:

flutter:“List”类型不是“List>”类型的子类型

我一直在处理 Dart 中的“不是子类型”错误,我终于能够使来自 REST 接口(interface)的 json 数据的所有转换正确。

谁能告诉我,为什么它在 Flutter 中轰炸,但在 Dart 中却没有?我该如何解决这个问题?

Future<>> callLogin() async {
return http.get(
"http://www.somesite.com")
.then((response) {
thử {
List l = new List();
final List<>> responseJson =
json.decode(response.body)['attendees'];
responseJson.forEach((f) => l.add(new Attendee.fromJson(f)));
return l;
} bắt (e) {
print(e); // Just print the error, for SO
}
});

class Attendee {
String nameFirst;
String nameLast;
String company;
...
factory Attendee.fromJson(Map json) {
return new Attendee(
nameLast: json['nameLast'],
nameFirst: json['tnameFirst'],
company: json['company'],
city: json['city'],
state: json['state'],
country: json['country'],
);
}


class AttendeeSearch extends StatefulWidget {
AttendeeSearch({Key key, this.title}) : super(key: key);
final String title;

@ghi đè
_AttendeeSearchPageState createState() => new
_AttendeeSearchPageState();
}

class _AttendeeSearchPageState extends State {

String search;

final _suggestions = new List();
final _smallerFont = const TextStyle(fontSize: 12.0);
final formKey = new GlobalKey();

void _submit() {
final form = formKey.currentState;
if (form.validate()) {
form.save();
}
AttendeeSummaryRequest asr = new AttendeeSummaryRequest();
setState(() {
asr.callLogin().then((item) { // Calling WebService
setState(() {
_suggestions.addAll(item);
});
});
});
}

câu trả lời hay nhất

对于遇到此问题的任何人,我做了以下操作......

Future<>> callLogin() async {
return http.get(
"http://www.somesite.com")
.then((response) {
thử {
List l = new List();

// final Map responseJson = // REPLACED
final dynamic responseJson = // <<== REMOVED CAST to Map
//
json.decode(response.body)['attendees'];
responseJson.forEach((f) => l.add(new Attendee.fromJson(f)));
return l;
} bắt (e) {
print(e); // Just print the error, for SO
}
});

通常我不会尝试回答我自己的问题。而且,在这种情况下,我仍然没有真正的答案,为什么 Flutter 的行为与从 Dart main 运行代码不同。我正在从 Android Studio 运行它们。所以,我假设 Dart 在这两种情况下都是相同的版本。但是,这就是我接下来要看的地方。如果我有更多信息,我会发布。

关于Dart 代码在我的 Flutter 应用程序中表现不同。列表<动态>' is not a subtype of type ' 列表< map <字符串,动态>>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50729769/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress