补充
This commit is contained in:
@@ -667,7 +667,10 @@ class ChatSessionNotifier extends Notifier<ChatSessionState>
|
||||
Future<void> _savePinnedNotes() async {
|
||||
try {
|
||||
final db = AppDatabase.instance;
|
||||
final pinnedSessions = state.sessions.where((s) => s.isPinnedNote).toList();
|
||||
// 使用 linkedNoteId != null 过滤,确保类型安全,避免空指针异常
|
||||
final pinnedSessions = state.sessions
|
||||
.where((s) => s.linkedNoteId != null)
|
||||
.toList();
|
||||
|
||||
// 先清空旧数据再批量写入
|
||||
await db.clearPinnedNotes();
|
||||
@@ -675,8 +678,10 @@ class ChatSessionNotifier extends Notifier<ChatSessionState>
|
||||
if (pinnedSessions.isEmpty) return;
|
||||
|
||||
final entries = pinnedSessions.map((s) {
|
||||
// linkedNoteId 已通过 where 过滤确保非空
|
||||
final noteId = s.linkedNoteId!;
|
||||
return PinnedNotesCompanion.insert(
|
||||
noteId: Value(s.linkedNoteId!),
|
||||
noteId: Value(noteId),
|
||||
title: Value(s.name),
|
||||
preview: Value(s.lastMessage),
|
||||
createdAt: Value(DateTime.now()),
|
||||
|
||||
Reference in New Issue
Block a user