我正在尝试取一个 1-7 整数值并使用枚举为每个值打印出一天。
我在 firestore 的类映射中遇到错误,“不是封闭类中的字段”
因此,如果传入 1,则给出“星期一” 如果传入 2,则给出“星期二”
enum _Days {
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}
class HeadingItem implements ListItem {
String _weekday;
final int time;
final DocumentReference reference;
set day(int weekday) {
var value = _Days.values[weekday - 1].toString();
var idx = value.indexOf(".") + 1;
var result = value.substring(idx, value.length);
_weekday = result;
}
String get day {
return _weekday;
}
HeadingItem.fromMap(Map<String, dynamic> map, {this.reference})
: assert(map['day'] != null),
assert(map['time'] != null),
day = map['day'], // 'day' isn't a field in the enclosing class <--- this is the error that im stuck on...
time = map['time'];
HeadingItem.fromSnapshot(DocumentSnapshot snapshot) : this.fromMap(snapshot.data, reference: snapshot.reference);
}
最佳答案
改变
String get day {
return _weekday;
}
为此
String day = _weekday;
关于dart - 使用 getter 和 setter 从 1-7 个整数创建字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53124685/