statistics_screen.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import '../services/bluetooth_service.dart';
  4. class StatisticsScreen extends ConsumerWidget {
  5. const StatisticsScreen({super.key});
  6. @override
  7. Widget build(BuildContext context, WidgetRef ref) {
  8. final machineState = ref.watch(bluetoothServiceProvider);
  9. return Scaffold(
  10. appBar: AppBar(title: const Text('Statistics')),
  11. body: ListView(
  12. padding: const EdgeInsets.all(16),
  13. children: [
  14. _StatTile(
  15. label: 'Total Shots',
  16. value: '${machineState.shotCounter}',
  17. icon: Icons.coffee,
  18. ),
  19. _StatTile(
  20. label: 'Grinder Cycles',
  21. value: '${machineState.grinderCounter}',
  22. icon: Icons.settings_input_component,
  23. ),
  24. const Divider(),
  25. const Padding(
  26. padding: EdgeInsets.all(16.0),
  27. child: Text(
  28. 'Shot counter is tracked on this device. Grinder counter is reported directly by the meCoffee hardware.',
  29. style: TextStyle(color: Colors.grey, fontSize: 12),
  30. textAlign: TextAlign.center,
  31. ),
  32. ),
  33. ],
  34. ),
  35. );
  36. }
  37. }
  38. class _StatTile extends StatelessWidget {
  39. final String label;
  40. final String value;
  41. final IconData icon;
  42. const _StatTile({
  43. required this.label,
  44. required this.value,
  45. required this.icon,
  46. });
  47. @override
  48. Widget build(BuildContext context) {
  49. return ListTile(
  50. leading: Icon(icon, color: Colors.orangeAccent),
  51. title: Text(label),
  52. trailing: Text(
  53. value,
  54. style: const TextStyle(
  55. fontSize: 20,
  56. fontWeight: FontWeight.bold,
  57. ),
  58. ),
  59. );
  60. }
  61. }