Skip to content

When extend with an real class (not Object), got the error "The class 'TumblrPostEntity' doesn't have an unnamed constructor.". #256

Closed
@jaggerwang

Description

@jaggerwang

Problem

As the title. All the examples are using class extends from Object, so I have no reference.

The class 'TumblrPostEntity' doesn't have an unnamed constructor.

Code

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;
  final String shortUrl;
  final String type;
  final String format;
  final List<String> tags;
  final String reblogKey;
  final _TumblrPostSource source;
  final bool isLiked;
  final String creator;
  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) =>
      _$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,
          isLiked: isLiked,
          creator: creator,
          postAt: postAt,
        );

  factory TumblrTextPostEntity.fromJson(Map<String, dynamic> json) =>
      _$TumblrTextPostEntityFromJson(json);

  @override
  String toString() => 'TumblrTextPostEntity${toJson()}';
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions