/
siblun
/
ReadFlow
Обзор
Документация
Войти
/
siblun
/
ReadFlow
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
lib/domain/models/book_model.dart
61 строка
2 KB
siblun
Add docs
21 апр 2026, 16:13
21 апр 2026, 16:13
c40d018
Код
Авторство
О чём код?
enum BookStatus { reading, finished, planned } /// Сущность книги в системе. /// Содержит бизнес-логику для расчета прогресса и состояния чтения. class Book { final String id; final String title; final String author; final int totalPages; final int currentPage; final BookStatus status; final String? coverPath; final DateTime dateAdded; final DateTime? dateFinished; Book({ required this.id, required this.title, required this.author, required this.totalPages, this.currentPage = 0, this.status = BookStatus.planned, this.coverPath, DateTime? dateAdded, this.dateFinished, }) : dateAdded = dateAdded ?? DateTime.now(); double get progressPercent { if (totalPages == 0) return 0; return ((currentPage / totalPages) * 100).clamp(0, 100); } bool get isFinished => status == BookStatus.finished || currentPage >= totalPages; int get remainingPages { final remaining = totalPages - currentPage; return remaining >= 0 ? remaining : 0; } Book copyWith({ String? title, String? author, int? totalPages, int? currentPage, BookStatus? status, String? coverPath, DateTime? dateAdded, DateTime? dateFinished, }) { return Book( id: id, title: title ?? this.title, author: author ?? this.author, totalPages: totalPages ?? this.totalPages, currentPage: currentPage ?? this.currentPage, status: status ?? this.status, coverPath: coverPath ?? this.coverPath, dateAdded: dateAdded ?? this.dateAdded, dateFinished: dateAdded ?? this.dateFinished, ); } }