Skip to main content
The Book class represents a book entity in the ReUCM system, containing all metadata, chapter information, and a reference to the source portal.

Class definition

class Book {
  final String id;
  final String url;
  final String title;
  final List<Author> authors;
  final String? annotation;
  final bool isFinished;
  final DateTime lastUpdateTime;
  final String? coverUrl;
  final List<Genre> genres;
  final Series? series;
  final List<String>? tags;
  final int? textLength;
  final List<Chapter> chapters = [];
  final Portal portal;

  Book({
    required this.id,
    required this.url,
    required this.title,
    required this.authors,
    this.annotation,
    required this.isFinished,
    required this.lastUpdateTime,
    this.coverUrl,
    required this.genres,
    this.series,
    this.tags,
    this.textLength,
    required this.portal,
  });
}

Properties

id
String
required
Unique identifier for the book within the portal.
url
String
required
The URL where the book can be accessed on the portal.
title
String
required
The title of the book.
authors
List<Author>
required
List of authors who wrote the book.
annotation
String?
Optional description or summary of the book.
isFinished
bool
required
Indicates whether the book is complete or still being written.
lastUpdateTime
DateTime
required
The timestamp of the last update to the book.
coverUrl
String?
Optional URL to the book’s cover image.
genres
List<Genre>
required
List of genres associated with the book.
series
Series?
Optional series information if the book is part of a series.
tags
List<String>?
Optional list of tags or keywords associated with the book.
textLength
int?
Optional total length of the book text in characters or words.
chapters
List<Chapter>
required
List of chapters in the book. Initialized as an empty list.
portal
Portal
required
Reference to the portal from which this book originates.

Constructor

Book({
  required String id,
  required String url,
  required String title,
  required List<Author> authors,
  String? annotation,
  required bool isFinished,
  required DateTime lastUpdateTime,
  String? coverUrl,
  required List<Genre> genres,
  Series? series,
  List<String>? tags,
  int? textLength,
  required Portal portal,
})
Creates a new Book instance with the provided metadata.

Usage example

final book = Book(
  id: '12345',
  url: 'https://example.com/books/12345',
  title: 'The Example Book',
  authors: [
    Author(name: 'John Doe', url: 'https://example.com/authors/johndoe'),
  ],
  annotation: 'An example book demonstrating the Book model.',
  isFinished: true,
  lastUpdateTime: DateTime(2024, 3, 15),
  coverUrl: 'https://example.com/covers/12345.jpg',
  genres: [
    Genre(name: 'Fiction'),
    Genre(name: 'Adventure'),
  ],
  series: Series(name: 'Example Series', number: 1),
  tags: ['adventure', 'example'],
  textLength: 150000,
  portal: myPortal,
);

// Add chapters to the book
book.chapters.add(Chapter(
  title: 'Chapter 1: The Beginning',
  content: 'Once upon a time...',
));

print('Book: ${book.title} by ${book.authors.first.name}');
print('Status: ${book.isFinished ? "Complete" : "In Progress"}');
print('Chapters: ${book.chapters.length}');

Build docs developers (and LLMs) love