在super()
的构造函数中调用TumblrTextPostEntity
时出现错误“ [dart]类'TumblrPostEntity'没有未命名的构造函数。”。
tumblr_post.dart
import 'package:meta/meta.dart';
import 'package:json_annotation/json_annotation.dart';
part 'tumblr_post.g.dart';
@JsonSerializable()
@immutable
class TumblrPostEntity extends Object with _$TumblrPostEntitySerializerMixin {
final int id;
final String url;
@JsonKey(name: 'short_url')
final String shortUrl;
final String type;
final String format;
final List<String> tags;
@JsonKey(name: 'reblog_key')
final String reblogKey;
final _TumblrPostSource source;
@JsonKey(name: 'is_liked')
final bool isLiked;
final String creator;
@JsonKey(name: 'post_at')
final DateTime postAt;
TumblrPostEntity({
this.id = 0,
this.url = '',
this.shortUrl = '',
this.type = '',
this.format = '',
this.tags = const [],
this.reblogKey = '',
source,
this.isLiked = false,
this.creator = '',
postAt,
}) : this.source = source ?? _TumblrPostSource(),
this.postAt = postAt ?? DateTime.fromMillisecondsSinceEpoch(0);
factory TumblrPostEntity.fromJson(Map<String, dynamic> json) {
json['source'] = _TumblrPostSource.fromJson(json['source']);
json['post_at'] = DateTime.parse(json['post_at']);
return _$TumblrPostEntityFromJson(json);
}
@override
String toString() => 'TumblrPostEntity${toJson()}';
}
@JsonSerializable()
@immutable
class _TumblrPostSource extends Object with _$_TumblrPostSourceSerializerMixin {
final String title;
final String url;
_TumblrPostSource({
this.title = '',
this.url = '',
});
factory _TumblrPostSource.fromJson(Map<String, dynamic> json) =>
_$_TumblrPostSourceFromJson(json);
@override
String toString() => '_TumblrPostSource${toJson()}';
}
@JsonSerializable()
@immutable
class TumblrTextPostEntity extends TumblrPostEntity
with _$TumblrTextPostEntitySerializerMixin {
final String title;
final String body;
TumblrTextPostEntity({
id = 0,
url = '',
shortUrl = '',
type = '',
format = '',
tags = const [],
reblogKey = '',
source = 0,
isLiked = false,
creator = '',
postAt,
this.title = '',
this.body = '',
}) : super(
id: id,
url: url,
shortUrl: shortUrl,
type: type,
format: format,
tags: tags,
reblogKey: reblogKey,
source: source ?? _TumblrPostSource(),
isLiked: isLiked,
creator: creator,
postAt: postAt ?? DateTime.fromMillisecondsSinceEpoch(0),
);
factory TumblrTextPostEntity.fromJson(Map<String, dynamic> json) {
json['source'] = _TumblrPostSource.fromJson(json['source']);
json['post_at'] = DateTime.parse(json['post_at']);
return _$TumblrTextPostEntityFromJson(json);
}
@override
String toString() => 'TumblrTextPostEntity${toJson()}';
}
tumblr_post.g.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'tumblr_post.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
TumblrPostEntity _$TumblrPostEntityFromJson(Map<String, dynamic> json) {
return new TumblrPostEntity(
id: json['id'] as int,
url: json['url'] as String,
shortUrl: json['short_url'] as String,
type: json['type'] as String,
format: json['format'] as String,
tags: (json['tags'] as List)?.map((e) => e as String)?.toList(),
reblogKey: json['reblog_key'] as String,
source: json['source'],
isLiked: json['is_liked'] as bool,
creator: json['creator'] as String,
postAt: json['post_at']);
}
abstract class _$TumblrPostEntitySerializerMixin {
int get id;
String get url;
String get shortUrl;
String get type;
String get format;
List<String> get tags;
String get reblogKey;
_TumblrPostSource get source;
bool get isLiked;
String get creator;
DateTime get postAt;
Map<String, dynamic> toJson() => <String, dynamic>{
'id': id,
'url': url,
'short_url': shortUrl,
'type': type,
'format': format,
'tags': tags,
'reblog_key': reblogKey,
'source': source,
'is_liked': isLiked,
'creator': creator,
'post_at': postAt?.toIso8601String()
};
}
_TumblrPostSource _$_TumblrPostSourceFromJson(Map<String, dynamic> json) {
return new _TumblrPostSource(
title: json['title'] as String, url: json['url'] as String);
}
abstract class _$_TumblrPostSourceSerializerMixin {
String get title;
String get url;
Map<String, dynamic> toJson() =>
<String, dynamic>{'title': title, 'url': url};
}
TumblrTextPostEntity _$TumblrTextPostEntityFromJson(Map<String, dynamic> json) {
return new TumblrTextPostEntity(
id: json['id'] as int,
url: json['url'] as String,
shortUrl: json['short_url'] as String,
type: json['type'] as String,
format: json['format'] as String,
tags: (json['tags'] as List)?.map((e) => e as String)?.toList(),
reblogKey: json['reblog_key'] as String,
source: json['source'],
isLiked: json['is_liked'] as bool,
creator: json['creator'] as String,
postAt: json['post_at'],
title: json['title'] as String,
body: json['body'] as String);
}
abstract class _$TumblrTextPostEntitySerializerMixin {
int get id;
String get url;
String get shortUrl;
String get type;
String get format;
List<String> get tags;
String get reblogKey;
_TumblrPostSource get source;
bool get isLiked;
String get creator;
DateTime get postAt;
String get title;
String get body;
Map<String, dynamic> toJson() => <String, dynamic>{
'id': id,
'url': url,
'short_url': shortUrl,
'type': type,
'format': format,
'tags': tags,
'reblog_key': reblogKey,
'source': source,
'is_liked': isLiked,
'creator': creator,
'post_at': postAt?.toIso8601String(),
'title': title,
'body': body
};
}