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

            Line data    Source code
       1              : import 'package:amadeus_proto/constants.dart';
       2              : import 'package:amadeus_proto/exercises/providers/note_placement_provider.dart';
       3              : import 'package:flutter/material.dart';
       4              : import 'package:provider/provider.dart';
       5              : 
       6              : /// Widget to create a Dragable Target Item
       7              : ///
       8              : /// - [imagePath] is a [String] that corresponds to the image filepath
       9              : /// - [answer] is the [String] that corresponds to the data of this item
      10              : ///
      11              : /// This widget will take any data that will be dropped on it, and will compare
      12              : /// the data with the widget answer.
      13              : /// If the data corresponds to the answer, it will call the metjod [selectGoodAnswer]
      14              : /// of the [NotePlacementProvider] and then set the next question
      15              : class DragTargetItem extends StatefulWidget {
      16            0 :   const DragTargetItem(
      17              :       {super.key, required this.imagePath, required this.answer});
      18              : 
      19              :   final String imagePath;
      20              :   final String answer;
      21              : 
      22            0 :   @override
      23            0 :   State<DragTargetItem> createState() => _DragTargetItemState();
      24              : }
      25              : 
      26              : class _DragTargetItemState extends State<DragTargetItem> {
      27              :   bool isDropped = false;
      28              :   bool isAvailable = true;
      29              : 
      30            0 :   @override
      31              :   Widget build(BuildContext context) {
      32            0 :     final NotePlacementProvider theory = context.watch<NotePlacementProvider>();
      33            0 :     if (theory.nbAnswer == 0) {
      34            0 :       isDropped = false;
      35            0 :       isAvailable = true;
      36              :     }
      37              : 
      38            0 :     return DragTarget<String>(
      39            0 :       builder: (
      40              :         BuildContext context,
      41              :         List<dynamic> accepted,
      42              :         List<dynamic> rejected,
      43              :       ) {
      44            0 :         return SizedBox(
      45              :           height: 75,
      46              :           width: 75,
      47            0 :           child: Center(
      48            0 :               child: Container(
      49              :                   height: 50,
      50              :                   width: 50,
      51              :                   decoration: const BoxDecoration(
      52              :                       color: Color.fromARGB(255, 235, 239, 255),
      53              :                       borderRadius:
      54              :                           BorderRadius.all(Radius.circular(smallBorderRadius)),
      55              :                       boxShadow: [
      56              :                         BoxShadow(
      57              :                             color: Colors.black54,
      58              :                             blurRadius: 2,
      59              :                             offset: Offset(0, 5),
      60              :                             blurStyle: BlurStyle.solid)
      61              :                       ]),
      62            0 :                   child: (isDropped)
      63            0 :                       ? Image.asset(widget.imagePath, width: 175)
      64              :                       : const Icon(
      65              :                           Icons.question_mark,
      66              :                           size: 30,
      67              :                         ))),
      68              :         );
      69              :       },
      70            0 :       onAcceptWithDetails: (DragTargetDetails<String> details) {
      71            0 :         if (!isAvailable) {
      72              :           return;
      73              :         }
      74            0 :         if (details.data != widget.answer) {
      75            0 :           theory.answer = widget.answer;
      76            0 :           theory.verify(details.data);
      77              :           return;
      78              :         }
      79            0 :         isDropped = true;
      80            0 :         isAvailable = false;
      81            0 :         theory.selectGoodAnswer();
      82            0 :         if (theory.nbAnswer == 0) {
      83            0 :           isDropped = false;
      84            0 :           isAvailable = true;
      85              :         }
      86              :       },
      87              :     );
      88              :   }
      89              : }
        

Generated by: LCOV version 2.3-1