51 lines
1.4 KiB
Dart
51 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:fl_chart/fl_chart.dart';
|
|
import '../../models/todo.dart';
|
|
|
|
class StatsView extends StatelessWidget {
|
|
final List<Todo> todos;
|
|
|
|
const StatsView({super.key, required this.todos});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final completedTodos = todos.where((todo) => todo.isCompleted).length;
|
|
final totalTodos = todos.length;
|
|
final completionRate = totalTodos > 0
|
|
? (completedTodos / totalTodos * 100).toStringAsFixed(1)
|
|
: '0.0';
|
|
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
'Completion Rate: $completionRate%',
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
),
|
|
const SizedBox(height: 20),
|
|
SizedBox(
|
|
height: 200,
|
|
child: PieChart(
|
|
PieChartData(
|
|
sections: [
|
|
PieChartSectionData(
|
|
value: completedTodos.toDouble(),
|
|
title: 'Completed',
|
|
color: Colors.green,
|
|
),
|
|
PieChartSectionData(
|
|
value: (totalTodos - completedTodos).toDouble(),
|
|
title: 'Pending',
|
|
color: Colors.red,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|