76aff4ea9e
A small cloud-upload glyph appears next to any row whose id has a queued offline write (offline-created temp ids and pending edits both count). Tooltip reads "Pending sync — will save when online". Renders nothing during normal online operation so the list stays clean. - DB: `watchPendingIds(domain)` streams the union of target_id and temp_id across the queue, scoped per domain. - Per-domain Riverpod stream providers for notes / tasks / projects. - New `PendingSyncBadge` widget — used by KnowledgeItemCard (both list and grid variants), `_ProjectCard`, and `_TaskRow` in the project workspace. flutter analyze clean; 21 tests pass. Closes #147 — all four phases of Tier 2 offline mode are in place. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
98 lines
3.1 KiB
Dart
98 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:lucide_icons/lucide_icons.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import '../../data/local/database.dart';
|
|
import '../../data/models/project.dart';
|
|
import '../../providers/projects_provider.dart';
|
|
import '../../widgets/pending_sync_badge.dart';
|
|
|
|
class ProjectsScreen extends ConsumerWidget {
|
|
const ProjectsScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final projectsAsync = ref.watch(projectsProvider);
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Projects')),
|
|
body: projectsAsync.when(
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
error: (e, _) => Center(child: Text('Error: $e')),
|
|
data: (projects) => projects.isEmpty
|
|
? const Center(child: Text('No projects yet.'))
|
|
: RefreshIndicator(
|
|
onRefresh: () => ref.read(projectsProvider.notifier).refresh(),
|
|
child: ListView.separated(
|
|
itemCount: projects.length,
|
|
separatorBuilder: (_, _) => const Divider(height: 1),
|
|
itemBuilder: (_, i) => _ProjectCard(project: projects[i]),
|
|
),
|
|
),
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () => context.push('/projects/new'),
|
|
tooltip: 'New project',
|
|
child: const Icon(LucideIcons.plus),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ProjectCard extends StatelessWidget {
|
|
final Project project;
|
|
const _ProjectCard({required this.project});
|
|
|
|
Color _statusColor(BuildContext context) => switch (project.status) {
|
|
'completed' => Colors.blue,
|
|
'archived' => Colors.grey,
|
|
_ => Theme.of(context).colorScheme.primary,
|
|
};
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListTile(
|
|
title: Row(
|
|
children: [
|
|
Flexible(child: Text(project.title)),
|
|
PendingSyncBadge(domain: kSyncDomainProjects, id: project.id),
|
|
],
|
|
),
|
|
subtitle: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (project.description?.isNotEmpty == true)
|
|
Text(
|
|
project.description!,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
if (project.goal?.isNotEmpty == true)
|
|
Text(
|
|
project.goal!,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.bodySmall
|
|
?.copyWith(fontStyle: FontStyle.italic),
|
|
),
|
|
],
|
|
),
|
|
trailing: Chip(
|
|
label: Text(
|
|
project.status,
|
|
style: TextStyle(
|
|
fontSize: 11,
|
|
color: _statusColor(context),
|
|
),
|
|
),
|
|
padding: EdgeInsets.zero,
|
|
visualDensity: VisualDensity.compact,
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
),
|
|
onTap: () => context.push('/projects/${project.id}/tasks'),
|
|
);
|
|
}
|
|
}
|