LCOV - code coverage report
Current view: top level - lib/design/generic - base_swipe_widget.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 37 0.0 %
Date: 2024-10-04 11:09:33 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/controller/flow_state_machine.dart';
       5             : import 'package:app_finance/_classes/herald/app_locale.dart';
       6             : import 'package:app_finance/_classes/storage/app_data.dart';
       7             : import 'package:app_finance/_classes/structure/navigation/app_route.dart';
       8             : import 'package:app_finance/_configs/theme_helper.dart';
       9             : import 'package:app_finance/design/wrapper/text_wrapper.dart';
      10             : import 'package:flutter/material.dart';
      11             : import 'package:flutter_swipe_action_cell/core/cell.dart';
      12             : import 'package:provider/provider.dart';
      13             : 
      14             : class BaseSwipeWidget extends StatelessWidget {
      15             :   final String uuid;
      16             :   final String? routePath;
      17             :   final Widget child;
      18             :   final double height;
      19             : 
      20           0 :   const BaseSwipeWidget({
      21             :     super.key,
      22             :     required this.child,
      23             :     required this.uuid,
      24             :     required this.routePath,
      25             :     this.height = 35,
      26             :   });
      27             : 
      28           0 :   Widget _getIcon(IconData icon, Color bgColor, Color color, String tooltip) {
      29           0 :     final indent = ThemeHelper.getIndent(0.5);
      30           0 :     return MouseRegion(
      31             :       cursor: SystemMouseCursors.click,
      32           0 :       child: Tooltip(
      33             :         message: tooltip,
      34           0 :         child: Container(
      35           0 :           padding: EdgeInsets.fromLTRB(1.5 * indent, indent, 1.5 * indent, indent),
      36           0 :           height: height,
      37           0 :           decoration: BoxDecoration(color: bgColor, borderRadius: BorderRadius.circular(25)),
      38           0 :           child: Icon(icon, color: color),
      39             :         ),
      40             :       ),
      41             :     );
      42             :   }
      43             : 
      44           0 :   @override
      45             :   Widget build(BuildContext context) {
      46           0 :     if (routePath == null || routePath == '') {
      47           0 :       return child;
      48             :     }
      49           0 :     NavigatorState nav = Navigator.of(context);
      50           0 :     return Consumer<AppData>(builder: (context, appState, _) {
      51           0 :       return Visibility(
      52           0 :         visible: appState.getByUuid(uuid)?.hidden == false,
      53           0 :         child: SwipeActionCell(
      54           0 :           key: ValueKey(key),
      55             :           backgroundColor: Colors.transparent,
      56           0 :           trailingActions: [
      57           0 :             SwipeAction(
      58           0 :               nestedAction: SwipeNestedAction(
      59           0 :                 content: MouseRegion(
      60             :                   cursor: SystemMouseCursors.click,
      61           0 :                   child: Container(
      62           0 :                     height: height,
      63           0 :                     decoration: BoxDecoration(
      64           0 :                       borderRadius: BorderRadius.circular(30),
      65             :                       color: Colors.red,
      66             :                     ),
      67           0 :                     child: OverflowBox(
      68             :                       maxWidth: double.infinity,
      69           0 :                       child: Row(
      70             :                         mainAxisAlignment: MainAxisAlignment.center,
      71           0 :                         children: [
      72             :                           const Icon(Icons.delete, color: Colors.white),
      73           0 :                           TextWrapper(AppLocale.labels.deleteTooltip, style: const TextStyle(color: Colors.white)),
      74             :                         ],
      75             :                       ),
      76             :                     ),
      77             :                   ),
      78             :                 ),
      79             :               ),
      80             :               color: Colors.transparent,
      81             :               closeOnTap: true,
      82           0 :               onTap: (_) => FlowStateMachine.deactivate(null, uuid: uuid, store: appState),
      83           0 :               content: _getIcon(Icons.delete, Colors.red, Colors.white, AppLocale.labels.deleteTooltip),
      84             :             ),
      85           0 :             SwipeAction(
      86             :               color: Colors.transparent,
      87             :               closeOnTap: true,
      88           0 :               onTap: (_) => nav.pushNamed(routePath!, arguments: {routeArguments.uuid: uuid}),
      89           0 :               content: _getIcon(Icons.edit, Colors.grey, Colors.white, AppLocale.labels.editTooltip),
      90             :             ),
      91             :           ],
      92           0 :           child: child,
      93             :         ),
      94             :       );
      95             :     });
      96             :   }
      97             : }

Generated by: LCOV version 1.14