Files
Kifi/kifi-app/lib/features/projects/presentation/projects_screen.dart

134 lines
5.3 KiB
Dart

import 'package:lucide_icons/lucide_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../providers/project_provider.dart';
import 'project_board_screen.dart';
import 'widgets/add_project_sheet.dart';
class ProjectsScreen extends ConsumerStatefulWidget {
const ProjectsScreen({super.key});
@override
ConsumerState<ProjectsScreen> createState() => _ProjectsScreenState();
}
class _ProjectsScreenState extends ConsumerState<ProjectsScreen> {
String _searchQuery = "";
@override
Widget build(BuildContext context) {
final projectsAsync = ref.watch(projectsProvider);
return Scaffold(
backgroundColor: Colors.grey[100],
appBar: AppBar(
title: const Text('Projects', style: TextStyle(fontWeight: FontWeight.bold)),
elevation: 0,
backgroundColor: Colors.white,
foregroundColor: Colors.black,
centerTitle: true,
),
body: Column(
children: [
Container(
color: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: TextField(
decoration: InputDecoration(
hintText: 'Search projects...',
prefixIcon: const Icon(LucideIcons.search, color: Colors.grey),
filled: true,
fillColor: Colors.grey[100],
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(16),
borderSide: BorderSide.none,
),
contentPadding: const EdgeInsets.symmetric(vertical: 14),
),
onChanged: (val) {
setState(() => _searchQuery = val);
},
),
),
Expanded(
child: projectsAsync.when(
data: (projects) {
final filteredProjects = projects.where((p) => p.name.toLowerCase().contains(_searchQuery.toLowerCase())).toList();
if (filteredProjects.isEmpty) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(LucideIcons.folderKanban, size: 48, color: Colors.grey.shade400),
const SizedBox(height: 12),
Text('No projects found.', style: TextStyle(color: Colors.grey.shade500)),
],
),
);
}
return ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: filteredProjects.length,
itemBuilder: (context, index) {
final p = filteredProjects[index];
return Card(
margin: const EdgeInsets.only(bottom: 12),
elevation: 0,
color: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
title: Text(p.name, style: const TextStyle(fontWeight: FontWeight.bold)),
subtitle: Text(p.description ?? 'No description', style: TextStyle(color: Colors.grey.shade600, fontSize: 13)),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: Icon(LucideIcons.edit, size: 18, color: Colors.grey.shade600),
onPressed: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (context) => AddProjectSheet(project: p),
);
},
),
Icon(Icons.chevron_right, color: Colors.grey.shade400),
],
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProjectBoardScreen(project: p),
),
);
},
),
);
},
);
},
loading: () => const Center(child: CircularProgressIndicator()),
error: (err, stack) => Center(child: Text('Error: $err')),
),
),
],
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (context) => const AddProjectSheet(),
);
},
icon: const Icon(Icons.add),
label: const Text('Add Project'),
),
);
}
}