exercise_indicator.dart 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:physigo/exercises/exercises_validation/models/exercise.dart';
  4. import 'package:physigo/exercises/exercises_validation/widgets/pose_detector.dart';
  5. class ExerciseIndicator extends StatelessWidget {
  6. const ExerciseIndicator({
  7. Key? key,
  8. required this.repCounter,
  9. required this.stepExerciseController,
  10. required this.exercise,
  11. }) : super(key: key);
  12. final Stream<int> repCounter;
  13. final Exercise exercise;
  14. final StreamController<StepExercise> stepExerciseController;
  15. @override
  16. Widget build(BuildContext context) {
  17. return Column(
  18. children: [
  19. StreamBuilder<StepExercise>(
  20. stream: stepExerciseController.stream,
  21. builder: (context, snapshot) {
  22. Color color;
  23. if (!snapshot.hasData) {
  24. color = Colors.black;
  25. } else {
  26. switch (snapshot.data!) {
  27. case StepExercise.notInPlace:
  28. color = Colors.black;
  29. break;
  30. case StepExercise.ready:
  31. color = Colors.green;
  32. break;
  33. case StepExercise.start:
  34. color = Colors.blue;
  35. break;
  36. case StepExercise.end:
  37. color = Colors.yellow;
  38. break;
  39. }
  40. }
  41. return Container(
  42. height: 100,
  43. width: 100,
  44. color: color,
  45. );
  46. },
  47. ),
  48. StreamBuilder<int>(
  49. stream: repCounter,
  50. builder: (context, snapshot) {
  51. var repCounter = 0;
  52. if (snapshot.hasData) {
  53. repCounter = snapshot.data!;
  54. }
  55. return Column(
  56. children: [
  57. Text(
  58. "Reps: ${repCounter % exercise.repetitions}/${exercise.repetitions}",
  59. style: const TextStyle(fontSize: 40),
  60. ),
  61. Text(
  62. "Sets: ${repCounter ~/ exercise.repetitions}/${exercise.sets}",
  63. style: const TextStyle(fontSize: 40),
  64. ),
  65. const SizedBox(height: 10),
  66. ElevatedButton(
  67. onPressed: () => Navigator.pop(context),
  68. style: ElevatedButton.styleFrom(
  69. padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 32),
  70. ),
  71. child: const Text("BACK",
  72. style: TextStyle(
  73. fontSize: 20,
  74. fontWeight: FontWeight.bold,
  75. letterSpacing: 1.3,
  76. )),
  77. )
  78. ],
  79. );
  80. },
  81. ),
  82. ],
  83. );
  84. }
  85. }