/
siblun
/
ReadFlow
Обзор
Документация
Войти
/
siblun
/
ReadFlow
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
lib/domain/models/note_model.dart
60 строк
2 KB
siblun
Add docs
21 апр 2026, 16:13
21 апр 2026, 16:13
c40d018
Код
Авторство
О чём код?
import 'dart:convert'; /// Заметка, привязанная к книге или конкретной сессии чтения. /// Поддерживает обычный текст и формат JSON Delta для расширенного редактирования. class Note { final String id; final String bookId; final String? sessionId; final String text; final String? location; final DateTime createdAt; final bool isQuote; Note({ required this.id, required this.bookId, this.sessionId, required this.text, this.location, required this.createdAt, this.isQuote = false, }); bool get hasLocation => location != null && location!.trim().isNotEmpty; bool get isShortNote => text.length < 100; String get preview { String plainText = ''; try { final List<dynamic> delta = jsonDecode(text); for (var op in delta) { if (op.containsKey('insert') && op['insert'] is String) { plainText += op['insert']; } } } catch (e) { plainText = text; } plainText = plainText.replaceAll('\n', ' ').trim(); return plainText.length > 50 ? '${plainText.substring(0, 50)}...' : plainText; } Note copyWith({ String? text, String? sessionId, String? location, bool? isQuote, }) { return Note( id: id, bookId: bookId, sessionId: sessionId ?? this.sessionId, text: text ?? this.text, location: location ?? this.location, createdAt: createdAt, isQuote: isQuote ?? this.isQuote, ); } }