LCOV - code coverage report
Current view: top level - lib/components/_core/widgets - draggable_frame.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 42 0.0 %
Date: 2024-10-04 11:12:13 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2023 The terCAD team. All rights reserved.
       2             : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
       3             : 
       4             : import 'package:app_finance/_classes/herald/app_design.dart';
       5             : import 'package:app_finance/_classes/herald/app_locale.dart';
       6             : import 'package:app_finance/_ext/build_context_ext.dart';
       7             : import 'package:app_finance/components/_core/components_builder_form.dart';
       8             : import 'package:app_finance/components/_core/component_data.dart';
       9             : import 'package:app_finance/components/_core/widgets/draggable_pointer.dart';
      10             : import 'package:app_finance/design/wrapper/confirmation_wrapper.dart';
      11             : import 'package:app_finance/design/wrapper/tap_widget.dart';
      12             : import 'package:flutter/material.dart';
      13             : import 'package:flutter_grid_layout/flutter_grid_layout.dart';
      14             : 
      15             : class DraggableFrame extends StatefulWidget {
      16             :   final Map<String, dynamic> data;
      17             :   final Function delete;
      18             :   final Function adjust;
      19             : 
      20           0 :   const DraggableFrame(
      21             :     this.data, {
      22             :     super.key,
      23             :     required this.delete,
      24             :     required this.adjust,
      25             :   });
      26             : 
      27           0 :   @override
      28           0 :   DraggableFrameState createState() => DraggableFrameState();
      29             : }
      30             : 
      31             : class DraggableFrameState extends State<DraggableFrame> {
      32             :   Color? color;
      33             :   bool isDrag = false;
      34             :   final _shift = componentData.shift;
      35             :   final _start = componentData.start;
      36             :   final _end = componentData.end;
      37             : 
      38           0 :   @override
      39             :   Widget build(BuildContext context) {
      40           0 :     final colorScheme = context.colorScheme;
      41           0 :     final frameLine = MouseRegion(
      42             :       cursor: SystemMouseCursors.move,
      43           0 :       onEnter: (_) => setState(() => color = colorScheme.primary.withOpacity(0.5)),
      44           0 :       onExit: (_) => setState(() => color = null),
      45           0 :       child: Container(
      46           0 :         color: color ?? colorScheme.secondary.withOpacity(0.2),
      47             :       ),
      48             :     );
      49           0 :     onDragStarted() => setState(() => isDrag = true);
      50           0 :     onDragEnd(_) => setState(() => isDrag = false);
      51           0 :     return Draggable<ComponentData>(
      52           0 :       data: {...widget.data, _shift: true},
      53             :       onDragStarted: onDragStarted,
      54             :       onDragEnd: onDragEnd,
      55           0 :       feedback: Container(color: context.colorScheme.primary, height: 40, width: 60),
      56           0 :       child: Padding(
      57             :         padding: const EdgeInsets.all(5),
      58           0 :         child: GridContainer(
      59           0 :           alignment: AppDesign.getAlignment<MainAxisAlignment>(),
      60             :           columns: const [7, 24, null, 24, 7],
      61             :           rows: const [7, 24, null, 24, 7],
      62           0 :           children: [
      63           0 :             GridItem(
      64             :                 start: const Size(0, 0),
      65             :                 end: const Size(4, 4),
      66           0 :                 child: Visibility(
      67           0 :                   visible: !isDrag,
      68           0 :                   child: ComponentsBuilderForm(widget.data, adjust: widget.adjust),
      69             :                 )),
      70           0 :             GridItem(
      71             :               start: const Size(2, 0),
      72             :               end: const Size(5, 1),
      73             :               order: 1,
      74             :               child: frameLine,
      75             :             ),
      76           0 :             GridItem(
      77             :               start: const Size(0, 2),
      78             :               end: const Size(1, 5),
      79             :               order: 1,
      80             :               child: frameLine,
      81             :             ),
      82           0 :             GridItem(
      83             :               start: const Size(4, 1),
      84             :               end: const Size(5, 3),
      85             :               order: 1,
      86             :               child: frameLine,
      87             :             ),
      88           0 :             GridItem(
      89             :               start: const Size(1, 4),
      90             :               end: const Size(3, 5),
      91             :               order: 1,
      92             :               child: frameLine,
      93             :             ),
      94           0 :             GridItem(
      95             :               start: const Size(3, 1),
      96             :               end: const Size(4, 2),
      97             :               order: 1,
      98           0 :               child: Visibility(
      99           0 :                 visible: !isDrag,
     100           0 :                 child: TapWidget(
     101           0 :                   tooltip: AppLocale.labels.deleteTooltip,
     102           0 :                   onTap: () => ConfirmationWrapper.show(
     103             :                     context,
     104           0 :                     () => widget.delete(widget.data[componentData.order]),
     105             :                   ),
     106           0 :                   child: Icon(
     107             :                     Icons.delete,
     108           0 :                     color: context.colorScheme.primary,
     109             :                   ),
     110             :                 ),
     111             :               ),
     112             :             ),
     113           0 :             GridItem(
     114             :               start: const Size(0, 0),
     115             :               end: const Size(2, 2),
     116             :               order: 2,
     117           0 :               child: DraggablePointer(
     118           0 :                 {...widget.data, _start: true},
     119             :                 onDragStarted: onDragStarted,
     120             :                 onDragEnd: onDragEnd,
     121             :               ),
     122             :             ),
     123           0 :             GridItem(
     124             :               start: const Size(3, 3),
     125             :               end: const Size(5, 5),
     126             :               order: 3,
     127           0 :               child: DraggablePointer(
     128           0 :                 {...widget.data, _end: true},
     129             :                 onDragStarted: onDragStarted,
     130             :                 onDragEnd: onDragEnd,
     131             :                 topLeft: false,
     132             :               ),
     133             :             ),
     134             :           ],
     135             :         ),
     136             :       ),
     137             :     );
     138             :   }
     139             : }

Generated by: LCOV version 1.14