4da36aa31d
Flutter Android client for FabledAssistant with: - Session-cookie auth via persistent cookie jar (Dio + cookie_jar) - OAuth/SSO login via in-app WebView (flutter_inappwebview) - Notes: list, detail (markdown render), create/edit - Tasks: list with status tabs, create/edit with priority - Chat: SSE streaming bubbles, conversation management - Quick Capture FAB for rapid note/task creation - Settings screen (change server URL, logout) - Android home screen widget → opens chat - Riverpod state management, go_router navigation Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
123 lines
4.2 KiB
Dart
123 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import '../../core/constants.dart';
|
|
import '../../providers/chat_provider.dart';
|
|
|
|
class ConversationsListScreen extends ConsumerWidget {
|
|
const ConversationsListScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final convsAsync = ref.watch(conversationsProvider);
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Chat')),
|
|
body: convsAsync.when(
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
error: (e, _) => Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text('Error: $e'),
|
|
TextButton(
|
|
onPressed: () => ref.invalidate(conversationsProvider),
|
|
child: const Text('Retry'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
data: (convs) {
|
|
if (convs.isEmpty) {
|
|
return const Center(
|
|
child: Text('No conversations yet. Tap + to start one.'));
|
|
}
|
|
return RefreshIndicator(
|
|
onRefresh: () => ref.refresh(conversationsProvider.future),
|
|
child: ListView.separated(
|
|
itemCount: convs.length,
|
|
separatorBuilder: (_, _) => const Divider(height: 1),
|
|
itemBuilder: (context, i) {
|
|
final conv = convs[i];
|
|
return ListTile(
|
|
leading: const Icon(Icons.chat_bubble_outline),
|
|
title: Text(conv.title),
|
|
subtitle: Text(
|
|
conv.updatedAt.toLocal().toString().substring(0, 16),
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
onTap: () => context.push(
|
|
Routes.chat.replaceFirst(':id', '${conv.id}'),
|
|
),
|
|
onLongPress: () async {
|
|
final confirm = await showDialog<bool>(
|
|
context: context,
|
|
builder: (_) => AlertDialog(
|
|
title: const Text('Delete conversation?'),
|
|
content: Text(conv.title),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, false),
|
|
child: const Text('Cancel'),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, true),
|
|
child: const Text('Delete'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
if (confirm == true) {
|
|
await ref
|
|
.read(conversationsProvider.notifier)
|
|
.delete(conv.id);
|
|
}
|
|
},
|
|
);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
heroTag: 'chat_fab',
|
|
onPressed: () => _newConversation(context, ref),
|
|
child: const Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _newConversation(BuildContext context, WidgetRef ref) async {
|
|
final controller = TextEditingController();
|
|
final title = await showDialog<String>(
|
|
context: context,
|
|
builder: (_) => AlertDialog(
|
|
title: const Text('New Conversation'),
|
|
content: TextField(
|
|
controller: controller,
|
|
decoration: const InputDecoration(hintText: 'Title'),
|
|
autofocus: true,
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Cancel'),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, controller.text.trim()),
|
|
child: const Text('Create'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
if (title != null && title.isNotEmpty) {
|
|
final conv =
|
|
await ref.read(conversationsProvider.notifier).create(title);
|
|
if (context.mounted) {
|
|
context.push(Routes.chat.replaceFirst(':id', '${conv.id}'));
|
|
}
|
|
}
|
|
}
|
|
}
|