77 lines
2.8 KiB
Dart
77 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:timetrack/features/projects/domain/project.dart';
|
|
import 'package:timetrack/features/projects/domain/projects_provider.dart';
|
|
|
|
class ProjectPickerSheet extends ConsumerWidget {
|
|
const ProjectPickerSheet({super.key});
|
|
|
|
static Future<Project?> show(BuildContext context) {
|
|
return showModalBottomSheet<Project>(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
|
),
|
|
builder: (_) => const ProjectPickerSheet(),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final projectsAsync = ref.watch(activeProjectsProvider);
|
|
|
|
return DraggableScrollableSheet(
|
|
initialChildSize: 0.5,
|
|
minChildSize: 0.3,
|
|
maxChildSize: 0.85,
|
|
expand: false,
|
|
builder: (context, scrollController) => Column(
|
|
children: [
|
|
const SizedBox(height: 8),
|
|
Container(
|
|
width: 40,
|
|
height: 4,
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.outlineVariant,
|
|
borderRadius: BorderRadius.circular(2),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'Select Project',
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Expanded(
|
|
child: projectsAsync.when(
|
|
data: (projects) => projects.isEmpty
|
|
? const Center(child: Text('No projects yet.\nCreate one in the Projects tab.', textAlign: TextAlign.center))
|
|
: ListView.builder(
|
|
controller: scrollController,
|
|
itemCount: projects.length,
|
|
itemBuilder: (context, index) {
|
|
final project = projects[index];
|
|
return ListTile(
|
|
leading: CircleAvatar(
|
|
backgroundColor: Color(project.colorValue),
|
|
radius: 12,
|
|
),
|
|
title: Text(project.name),
|
|
subtitle: project.description != null
|
|
? Text(project.description!, maxLines: 1, overflow: TextOverflow.ellipsis)
|
|
: null,
|
|
onTap: () => Navigator.pop(context, project),
|
|
);
|
|
},
|
|
),
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
error: (e, _) => Center(child: Text('Error: $e')),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|