gpt4 book ai didi

flutter - 请帮助我从这段代码中理解 fromMap 和 toMap ?

转载 作者:行者123 更新时间:2023-12-03 03:12:27 27 4
gpt4 key购买 nike

我从互联网上得到了这段代码,但我似乎无法理解它或在互联网上找到任何关于它的东西。

在下面的代码中 toMap 是一个返回 2 个项目的方法,这怎么可能?

什么是fromMap,它是用户创建的方法吗?我认为方法使用 {} 或 => 所以有点困惑。

另外,这里 map 的关键是什么? map 只能存储2类元素吗?一个是关键,一个是值(value)。或者它可以有一个键但有多个类别的值。

例如,可能有一个唯一的键,它可以帮助取出任务标题、时间、提醒数据、注释等作为 map 的值。

class Task {
String title;
bool completed;

Task({
this.title,
this.completed = false,
});

Task.fromMap(Map<String, dynamic> map): title = map['title'],completed = map['completed'];

updateTitle(title) {
this.title = title;
}

Map toMap() {
return {
'title': title,
'completed': completed,
};
}
}

最佳答案

In the code below toMap is a method that returns 2 items, How is that possible?



不,它返回 Map (有两个项目)。有关 map 的更多信息,请访问 here .

And what is fromMap, is it a user created method? I thought methods used {} or => so it is a bit confusing.


Task.fromMap(Map<String, dynamic> map)被称为“名为 constructor”。 : title = map['title'],completed = map['completed']部分是 initializer list

关于flutter - 请帮助我从这段代码中理解 fromMap 和 toMap ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58199782/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com