Skip to content

Abstract factory not linked #2008

@Levi-Lesches

Description

@Levi-Lesches

I have two classes: NoteTime (abstract), and Note, which has a final NoteTime time property.

The Note constructor looks like this:

/// Returns a new [Note] from a JSON object.
/// 
/// Uses `json ["message"]` for the message and passes `json["time"]` to [NoteTime.fromJson]
factory Note.fromJson(Map<String, dynamic> json) => Note (
	message: json ["message"],
	time: NoteTime.fromJson(json ["time"]),
);

Clicking on NoteTime.fromJson in the docs leads back to the Note constructor... any clue why?

Here's my NoteTime.fromJson:

/// Initializes a new instace from JSON.
/// 
/// Mainly looks at `json ["type"]` to choose which type of 
/// [NoteTime] it should instantiate, and then leaves the 
/// work to that subclasses `.fromJson` method. 
/// 
/// Example JSON: 
/// ```
/// {
/// 	"type": "period",
/// 	"repeats": false,
/// 	"period": "9",
/// 	"letter": "M",
/// }
/// ```
factory NoteTime.fromJson(Map<String, dynamic> json) {
	switch (stringToNoteTime [json ["type"]]) {
		case NoteTimeType.period: return PeriodNoteTime.fromJson(json);
		case NoteTimeType.subject: return SubjectNoteTime.fromJson(json);
		default: throw JsonUnsupportedObjectError(
			json,
			cause: "Invalid time for note: $json"
		);
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1A high priority bug; for example, a single project is unusable or has many test failures

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions