Add search, offline queue, app icon, and UI polish

- Collapsible search in notes and tasks: magnifying glass in AppBar
  expands to a text field inline; close button resets the filter
- Offline capture queue: failed quick-captures (NetworkException) are
  persisted to SharedPreferences and retried automatically on next
  successful submit or app start; badge shows pending count
- App icon: book-with-sparkle logo from FabledAssistant SVG rendered
  at all Android densities with adaptive icon (indigo #6366f1 bg)
- Dark mode subtitle fix: use colorScheme.onSurfaceVariant for note
  preview and conversation timestamp text
- Remove swipe-to-delete (accidental deletions); long-press remains
- Chat: SSE streaming reliability, polling fallback, title patching
- Settings: theme toggle (system/light/dark) persisted to prefs
- Notes: delete button in edit screen; body preview in list
- Tasks: fix delete dialog context; description search support

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 23:15:06 -05:00
parent 1fb792177e
commit 2a35fe5532
33 changed files with 854 additions and 282 deletions
+5
View File
@@ -6,6 +6,7 @@ import '../data/api/api_client.dart';
import '../data/api/auth_api.dart';
import '../data/api/chat_api.dart';
import '../data/api/notes_api.dart';
import '../data/api/quick_capture_api.dart';
import '../data/api/tasks_api.dart';
import '../data/repositories/auth_repository.dart';
import '../data/repositories/chat_repository.dart';
@@ -40,6 +41,10 @@ final chatApiProvider = Provider<ChatApi>((ref) {
return ChatApi(ref.watch(dioProvider));
});
final quickCaptureApiProvider = Provider<QuickCaptureApi>((ref) {
return QuickCaptureApi(ref.watch(dioProvider));
});
final authRepositoryProvider = Provider<AuthRepository>((ref) {
return AuthRepository(ref.watch(authApiProvider));
});
+29
View File
@@ -0,0 +1,29 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'settings_provider.dart';
final captureQueueProvider =
StateNotifierProvider<CaptureQueueNotifier, List<String>>(
(ref) => CaptureQueueNotifier(ref.watch(sharedPreferencesProvider)),
);
class CaptureQueueNotifier extends StateNotifier<List<String>> {
static const _key = 'capture_queue';
final SharedPreferences _prefs;
CaptureQueueNotifier(this._prefs)
: super(_prefs.getStringList(_key) ?? []);
Future<void> enqueue(String text) async {
final updated = [...state, text];
await _prefs.setStringList(_key, updated);
state = updated;
}
Future<void> dequeue(String text) async {
final updated = List<String>.from(state)..remove(text);
await _prefs.setStringList(_key, updated);
state = updated;
}
}
+71 -38
View File
@@ -4,6 +4,9 @@ import '../data/models/conversation.dart';
import '../data/models/message.dart';
import 'api_client_provider.dart';
// Separate StateProvider so UI re-builds immediately when streaming starts/stops.
final isStreamingProvider = StateProvider.family<bool, int>((ref, _) => false);
final conversationsProvider =
AsyncNotifierProvider<ConversationsNotifier, List<Conversation>>(
ConversationsNotifier.new);
@@ -28,71 +31,101 @@ class ConversationsNotifier extends AsyncNotifier<List<Conversation>> {
if (c.id != id) c,
]);
}
// Called after a message is sent to patch the server-generated title
// in-place without triggering a full reload or loading state.
void patchConversation(Conversation updated) {
final list = state.valueOrNull;
if (list == null) return;
state = AsyncData([
for (final c in list)
if (c.id == updated.id) updated else c,
]);
}
}
final messagesProvider = AsyncNotifierProvider.family<MessagesNotifier,
List<Message>, int>(MessagesNotifier.new);
class MessagesNotifier extends FamilyAsyncNotifier<List<Message>, int> {
bool _isStreaming = false;
bool get isStreaming => _isStreaming;
@override
Future<List<Message>> build(int arg) async {
return ref.watch(chatRepositoryProvider).getMessages(arg);
final (_, messages) =
await ref.watch(chatRepositoryProvider).getMessages(arg);
return messages;
}
Future<void> sendMessage(String content) async {
final conversationId = arg;
final convId = arg;
final repo = ref.read(chatRepositoryProvider);
final previousMessages = state.valueOrNull ?? [];
// Optimistically add the user message.
// Optimistic UI: show the user message + assistant placeholder immediately.
final userMsg = Message(
conversationId: conversationId,
conversationId: convId,
role: MessageRole.user,
content: content,
);
state = AsyncData([...state.valueOrNull ?? [], userMsg]);
// Add an empty assistant placeholder.
final placeholder = Message(
conversationId: conversationId,
conversationId: convId,
role: MessageRole.assistant,
content: '',
status: 'generating',
);
state = AsyncData([...state.requireValue, placeholder]);
state = AsyncData([...previousMessages, userMsg, placeholder]);
ref.read(isStreamingProvider(convId).notifier).state = true;
_isStreaming = true;
try {
// Step 1: POST the message (fires background generation on server).
await repo.sendMessage(conversationId, content);
// Step 2: Stream chunks and update the placeholder in place.
await for (final chunk in repo.streamGeneration(conversationId)) {
final msgs = state.requireValue;
final last = msgs.last.copyWith(content: msgs.last.content + chunk);
state = AsyncData([...msgs.sublist(0, msgs.length - 1), last]);
}
// Mark the assistant message as complete.
final msgs = state.requireValue;
final last = msgs.last.copyWith(status: 'complete');
state = AsyncData([...msgs.sublist(0, msgs.length - 1), last]);
// ── Step 1: POST the message. If this fails the server never got it. ──
await repo.sendMessage(convId, content);
} catch (e) {
// Remove the placeholder on error so the user can retry.
state = AsyncData([
for (final m in state.valueOrNull ?? [])
if (m.status != 'generating') m,
]);
state = AsyncData(previousMessages);
ref.read(isStreamingProvider(convId).notifier).state = false;
rethrow;
}
// ── Step 2: Stream the response (best effort — silent on failure). ──
bool streamedContent = false;
try {
await for (final chunk in repo.streamGeneration(convId)) {
streamedContent = true;
final msgs = state.requireValue;
final updated = msgs.last.copyWith(content: msgs.last.content + chunk);
state = AsyncData([...msgs.sublist(0, msgs.length - 1), updated]);
}
} catch (_) {
// SSE failed — fall through to the polling reload below.
}
// ── Step 3: Poll the API until we have a completed assistant response.
//
// If SSE delivered content the server is done; one reload suffices.
// If SSE delivered nothing, the LLM may still be generating — we retry
// with short delays so the response appears as soon as it's ready.
// A completed message is one whose status is not 'generating'.
try {
final maxAttempts = streamedContent ? 1 : 20;
for (var attempt = 0; attempt < maxAttempts; attempt++) {
if (attempt > 0) await Future.delayed(const Duration(seconds: 2));
final (conv, fresh) = await repo.getMessages(convId);
state = AsyncData(fresh);
ref.read(conversationsProvider.notifier).patchConversation(conv);
final done = fresh.any(
(m) => m.role == MessageRole.assistant && m.status != 'generating',
);
if (done) break;
}
} catch (_) {
// If every reload fails, at least clear the generating placeholder.
final msgs = state.valueOrNull;
if (msgs != null && msgs.isNotEmpty && msgs.last.status == 'generating') {
state = AsyncData([
...msgs.sublist(0, msgs.length - 1),
msgs.last.copyWith(status: 'complete'),
]);
}
} finally {
_isStreaming = false;
ref.read(isStreamingProvider(convId).notifier).state = false;
}
}
}
final isStreamingProvider = Provider.family<bool, int>((ref, convId) {
final notifier = ref.watch(messagesProvider(convId).notifier);
return notifier.isStreaming;
});
+31
View File
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
const _kServerUrl = 'server_url';
const _kThemeMode = 'theme_mode';
final sharedPreferencesProvider = Provider<SharedPreferences>((ref) {
throw UnimplementedError('Override in ProviderScope');
@@ -11,6 +13,35 @@ final cookiesPathProvider = Provider<String>((ref) {
throw UnimplementedError('Override in ProviderScope');
});
final themeModeProvider =
StateNotifierProvider<ThemeModeNotifier, ThemeMode>((ref) {
final prefs = ref.watch(sharedPreferencesProvider);
return ThemeModeNotifier(prefs);
});
class ThemeModeNotifier extends StateNotifier<ThemeMode> {
final SharedPreferences _prefs;
ThemeModeNotifier(this._prefs)
: super(_fromString(_prefs.getString(_kThemeMode)));
static ThemeMode _fromString(String? value) => switch (value) {
'light' => ThemeMode.light,
'dark' => ThemeMode.dark,
_ => ThemeMode.system,
};
Future<void> setMode(ThemeMode mode) async {
final value = switch (mode) {
ThemeMode.light => 'light',
ThemeMode.dark => 'dark',
_ => 'system',
};
await _prefs.setString(_kThemeMode, value);
state = mode;
}
}
final serverUrlProvider = StateNotifierProvider<ServerUrlNotifier, String?>((ref) {
final prefs = ref.watch(sharedPreferencesProvider);
return ServerUrlNotifier(prefs);