192 lines
5.9 KiB
Dart
192 lines
5.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../../../domain/models/task_item.dart';
|
|
import '../view_models/dashboard_view_model.dart';
|
|
|
|
class DashboardView extends StatelessWidget {
|
|
const DashboardView({super.key, required this.viewModel});
|
|
|
|
final DashboardViewModel viewModel;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListenableBuilder(
|
|
listenable: viewModel,
|
|
builder: (context, _) {
|
|
if (viewModel.isLoading) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
|
|
final tasks = viewModel.tasks;
|
|
|
|
return ListView(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
|
|
children: [
|
|
_buildSummaryCard(context),
|
|
const SizedBox(height: 16),
|
|
_buildCategoryFilter(context),
|
|
const SizedBox(height: 12),
|
|
if (tasks.isEmpty)
|
|
_buildEmptyState(context)
|
|
else
|
|
...tasks.map((task) => _buildTaskCard(context, task)),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _buildSummaryCard(BuildContext context) {
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
final textTheme = Theme.of(context).textTheme;
|
|
|
|
return Card(
|
|
color: colorScheme.surfaceContainerHighest.withAlpha(128),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
'Task Progress',
|
|
style: textTheme.titleMedium?.copyWith(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Text(
|
|
'${viewModel.completedCount}/${viewModel.totalCount}',
|
|
style: textTheme.titleMedium?.copyWith(
|
|
color: colorScheme.primary,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(8),
|
|
child: LinearProgressIndicator(
|
|
value: viewModel.completionProgress,
|
|
minHeight: 10,
|
|
backgroundColor: colorScheme.surfaceContainerHighest,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'${(viewModel.completionProgress * 100).round()}% completed',
|
|
style: textTheme.bodySmall?.copyWith(
|
|
color: colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildCategoryFilter(BuildContext context) {
|
|
return SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: Row(
|
|
children: viewModel.availableCategories.map((category) {
|
|
final isSelected = viewModel.selectedCategory == category;
|
|
return Padding(
|
|
padding: const EdgeInsets.only(right: 8.0),
|
|
child: FilterChip(
|
|
label: Text(category),
|
|
selected: isSelected,
|
|
onSelected: (_) => viewModel.setCategoryFilter(category),
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildTaskCard(BuildContext context, TaskItem task) {
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
return Card(
|
|
margin: const EdgeInsets.only(bottom: 8.0),
|
|
child: ListTile(
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
|
leading: Checkbox(
|
|
value: task.isCompleted,
|
|
onChanged: (_) => viewModel.toggleTaskCompletion(task),
|
|
),
|
|
title: Text(
|
|
task.title,
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w600,
|
|
decoration: task.isCompleted
|
|
? TextDecoration.lineThrough
|
|
: TextDecoration.none,
|
|
color: task.isCompleted ? colorScheme.outline : null,
|
|
),
|
|
),
|
|
subtitle: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (task.description.isNotEmpty) ...[
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
task.description,
|
|
style: TextStyle(
|
|
color: task.isCompleted ? colorScheme.outline : null,
|
|
),
|
|
),
|
|
],
|
|
const SizedBox(height: 6),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
|
decoration: BoxDecoration(
|
|
color: colorScheme.secondaryContainer,
|
|
borderRadius: BorderRadius.circular(6),
|
|
),
|
|
child: Text(
|
|
task.category,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: colorScheme.onSecondaryContainer,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
trailing: IconButton(
|
|
icon: const Icon(Icons.delete_outline),
|
|
tooltip: 'Delete task',
|
|
onPressed: () => viewModel.deleteTask(task.id),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildEmptyState(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 48.0),
|
|
child: Center(
|
|
child: Column(
|
|
children: [
|
|
Icon(
|
|
Icons.done_all,
|
|
size: 56,
|
|
color: theme.colorScheme.outlineVariant,
|
|
),
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
'No tasks in this category',
|
|
style: theme.textTheme.titleMedium?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|