LCOV - code coverage report
Current view: top level - lib/exercises - exercises_list.dart Coverage Total Hit
Test: lcov.info Lines: 0.0 % 47 0
Test Date: 2025-05-10 20:26:13 Functions: - 0 0

            Line data    Source code
       1              : import 'dart:async';
       2              : 
       3              : import 'package:amadeus_proto/api/routes/exercises.dart';
       4              : import 'package:amadeus_proto/api/utils/api_base.dart';
       5              : import 'package:amadeus_proto/api/utils/api_error.dart';
       6              : import 'package:amadeus_proto/api/widget/api_result_wrapper.dart';
       7              : import 'package:amadeus_proto/constants.dart';
       8              : import 'package:amadeus_proto/exercises/categories/dictation/note_finder/dictation_page.dart';
       9              : import 'package:amadeus_proto/exercises/categories/reading/note_reading/note_reading_page.dart';
      10              : import 'package:amadeus_proto/exercises/categories/rhythm/beats/rhythm_page.dart';
      11              : import 'package:amadeus_proto/exercises/categories/theory/accidental_recognition/accidental_recognition_page.dart';
      12              : import 'package:amadeus_proto/exercises/categories/theory/note_placement/theory_page.dart';
      13              : import 'package:amadeus_proto/exercises/exercise_widget.dart';
      14              : import 'package:amadeus_proto/exercises/exercises_page.dart';
      15              : import 'package:amadeus_proto/exercises/widget/previous_button.dart';
      16              : import 'package:amadeus_proto/api/models/exercise_info.dart';
      17              : import 'package:amadeus_proto/utils/either_extension.dart';
      18              : import 'package:either_dart/either.dart';
      19              : import 'package:amadeus_proto/utils/searchbar.dart';
      20              : import 'package:flutter/material.dart';
      21              : import 'package:localization/localization.dart';
      22              : 
      23              : class CategoriesExercises extends StatelessWidget {
      24            0 :   const CategoriesExercises({super.key, required this.category});
      25              : 
      26              :   final ExerciseCategoryEnum category;
      27              : 
      28            0 :   Future<Either<ApiError, List<ExerciseInfo>>> getExercise(
      29              :       ApiBase api) async {
      30            0 :     final exercises = await api.getExercisesByType(
      31            0 :       switch (category) {
      32            0 :         ExerciseCategoryEnum.RHYTHM => "Rhythm",
      33            0 :         ExerciseCategoryEnum.READING => "Reading",
      34            0 :         ExerciseCategoryEnum.LISTENING => "Dictation",
      35            0 :         ExerciseCategoryEnum.THEORY => "Theory",
      36              :       },
      37              :       null,
      38              :     );
      39              : 
      40            0 :     if (exercises.isLeft) {
      41              :       return exercises;
      42              :     }
      43              : 
      44            0 :     final futures = exercises.right.map((e) async {
      45            0 :       final result = await api.getExercise(e.id);
      46            0 :       return result.map((data) => e..exerciseData = data);
      47              :     });
      48              : 
      49            0 :     final results = await Future.wait(futures);
      50              : 
      51            0 :     return results.sequence();
      52              :   }
      53              : 
      54            0 :   @override
      55              :   Widget build(BuildContext context) {
      56            0 :     return Scaffold(
      57            0 :       body: Column(
      58            0 :         children: [
      59              :           const SizedBox(height: 35),
      60            0 :           Row(
      61            0 :             children: [
      62              :               const PreviousButton(),
      63            0 :               Text(
      64            0 :                 category.categoryName.i18n(),
      65              :                 style: const TextStyle(
      66              :                     color: Colors.black,
      67              :                     fontSize: largeTextSize,
      68              :                     fontWeight: FontWeight.bold),
      69              :               ),
      70              :             ],
      71              :           ),
      72              :           const SearchBarWidget(),
      73            0 :           Expanded(
      74            0 :             child: ApiResultWrapper(
      75            0 :               future: getExercise(ApiBase.read(context)),
      76            0 :               builder: (context, exercises) => ListView.builder(
      77              :                 shrinkWrap: true,
      78              :                 physics: const AlwaysScrollableScrollPhysics(),
      79            0 :                 itemCount: exercises.length,
      80            0 :                 itemBuilder: (BuildContext context, int index) {
      81            0 :                   return Padding(
      82              :                     padding: const EdgeInsets.all(smallPadding),
      83            0 :                     child: ExercisePreview(
      84            0 :                       info: exercises[index],
      85            0 :                       category: category,
      86              :                     ),
      87              :                   );
      88              :                 },
      89              :               ),
      90              :             ),
      91              :           ),
      92              :         ],
      93              :       ),
      94              :     );
      95              :   }
      96              : }
      97              : 
      98              : class ExercisePreview extends StatelessWidget {
      99            0 :   const ExercisePreview({
     100              :     super.key,
     101              :     required this.category,
     102              :     required this.info,
     103              :   });
     104              : 
     105              :   final ExerciseInfo info;
     106              :   final ExerciseCategoryEnum category;
     107              : 
     108            0 :   @override
     109              :   Widget build(BuildContext context) {
     110            0 :     return ExerciseWidget(
     111            0 :       data: info.exerciseData,
     112            0 :       exercisePage: (dynamic data) => switch ((category, info.name)) {
     113            0 :         (ExerciseCategoryEnum.RHYTHM, _) => RhythmPage(info: info),
     114            0 :         (ExerciseCategoryEnum.READING, _) => ReadingExercise(info: info),
     115            0 :         (ExerciseCategoryEnum.LISTENING, _) => DictationPage(info: info),
     116            0 :         (ExerciseCategoryEnum.THEORY, "Accidental Symbol") => AccidentalRecognitionPage(info: info),
     117            0 :         (ExerciseCategoryEnum.THEORY, _) => TheoryExercise(info: info),
     118              :       },
     119            0 :       iconPath: switch (category) {
     120            0 :         ExerciseCategoryEnum.RHYTHM =>
     121              :           'assets/FigmaDesign/Asset/SVG/Rhythm.svg',
     122            0 :         ExerciseCategoryEnum.READING =>
     123              :           'assets/FigmaDesign/Asset/SVG/Reading.svg',
     124            0 :         ExerciseCategoryEnum.LISTENING =>
     125              :           'assets/FigmaDesign/Asset/SVG/Listening.svg',
     126            0 :         ExerciseCategoryEnum.THEORY =>
     127              :           'assets/FigmaDesign/Asset/SVG/Theory.svg',
     128              :       },
     129              :     );
     130              :   }
     131              : }
        

Generated by: LCOV version 2.3-1