import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../providers/projects_provider.dart'; /// Dropdown for picking a project. Pass [value] as the current project id /// (null = no project) and [onChanged] to receive updates. class ProjectSelector extends ConsumerWidget { final int? value; final ValueChanged onChanged; final InputDecoration? decoration; const ProjectSelector({ super.key, required this.value, required this.onChanged, this.decoration, }); @override Widget build(BuildContext context, WidgetRef ref) { final projectsAsync = ref.watch(projectsProvider); return projectsAsync.when( loading: () => const LinearProgressIndicator(), error: (_, __) => const SizedBox.shrink(), data: (projects) { final active = projects.where((p) => p.status == 'active').toList(); return DropdownButtonFormField( value: value, decoration: decoration ?? const InputDecoration( labelText: 'Project (optional)', border: OutlineInputBorder(), ), items: [ const DropdownMenuItem( value: null, child: Text('No project'), ), ...active.map( (p) => DropdownMenuItem( value: p.id, child: Text(p.title, overflow: TextOverflow.ellipsis), ), ), ], onChanged: onChanged, ); }, ); } }