Files
sharedinbox/lib/ui/widgets/folder_drawer.dart
T
Thomas GüttlerandClaude Sonnet 4.6 e3ba18285d refactor: enforce always_use_package_imports across all lib files
Added lint rule to analysis_options.yaml and ran dart fix --apply to convert
125 relative imports in 33 files to package:sharedinbox/... style.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-24 16:30:59 +02:00

119 lines
4.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:sharedinbox/core/models/mailbox.dart';
import 'package:sharedinbox/di.dart';
/// Sorts INBOX first, Drafts second, then alphabetically.
int compareMailboxes(Mailbox a, Mailbox b) {
final pa = _priority(a);
final pb = _priority(b);
if (pa != pb) return pa.compareTo(pb);
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
}
int _priority(Mailbox mb) {
final upper = mb.path.toUpperCase();
if (upper == 'INBOX') return 0;
if (upper.contains('DRAFT')) return 1;
return 2;
}
/// Drawer showing all folders for [accountId].
/// Highlights [currentMailboxPath] when provided.
class FolderDrawer extends ConsumerWidget {
const FolderDrawer({
super.key,
required this.accountId,
this.currentMailboxPath,
});
final String accountId;
final String? currentMailboxPath;
@override
Widget build(BuildContext context, WidgetRef ref) {
final accountAsync = ref.watch(accountByIdProvider(accountId));
final mailboxRepo = ref.watch(mailboxRepositoryProvider);
return Drawer(
child: Column(
children: [
DrawerHeader(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primaryContainer,
),
child: Align(
alignment: Alignment.bottomLeft,
child: accountAsync.when(
loading: () => const CircularProgressIndicator(),
error: (_, __) => const Text('Account'),
data: (account) => Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
account?.displayName ?? '',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context)
.colorScheme
.onPrimaryContainer,
fontWeight: FontWeight.bold,
),
),
Text(
account?.email ?? '',
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimaryContainer,
fontSize: 12,
),
),
],
),
),
),
),
Expanded(
child: StreamBuilder(
stream: mailboxRepo.observeMailboxes(accountId),
builder: (ctx, snap) {
if (!snap.hasData) {
return const Center(child: CircularProgressIndicator());
}
final mailboxes = List.of(snap.data!)..sort(compareMailboxes);
return ListView(
padding: EdgeInsets.zero,
children: [
for (final mb in mailboxes)
ListTile(
leading: const Icon(Icons.folder),
title: Text(
mb.name,
style: mb.unreadCount > 0
? const TextStyle(fontWeight: FontWeight.bold)
: null,
),
selected: mb.path == currentMailboxPath,
trailing: mb.unreadCount > 0
? Badge(label: Text('${mb.unreadCount}'))
: null,
onTap: () {
Navigator.pop(context);
context.go(
'/accounts/$accountId/mailboxes'
'/${Uri.encodeComponent(mb.path)}/emails',
);
},
),
],
);
},
),
),
],
),
);
}
}