LCOV - code coverage report
Current view: top level - lib/design/generic - base_swipe_widget.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 34 37 91.9 %
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/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           1 :   const BaseSwipeWidget({
      21             :     super.key,
      22             :     required this.child,
      23             :     required this.uuid,
      24             :     required this.routePath,
      25             :     this.height = 35,
      26             :   });
      27             : 
      28           1 :   Widget _getIcon(IconData icon, Color bgColor, Color color, String tooltip) {
      29           1 :     final indent = ThemeHelper.getIndent(0.5);
      30           1 :     return MouseRegion(
      31             :       cursor: SystemMouseCursors.click,
      32           1 :       child: Tooltip(
      33             :         message: tooltip,
      34           1 :         child: Container(
      35           3 :           padding: EdgeInsets.fromLTRB(1.5 * indent, indent, 1.5 * indent, indent),
      36           1 :           height: height,
      37           2 :           decoration: BoxDecoration(color: bgColor, borderRadius: BorderRadius.circular(25)),
      38           1 :           child: Icon(icon, color: color),
      39             :         ),
      40             :       ),
      41             :     );
      42             :   }
      43             : 
      44           1 :   @override
      45             :   Widget build(BuildContext context) {
      46           3 :     if (routePath == null || routePath == '') {
      47           0 :       return child;
      48             :     }
      49           1 :     NavigatorState nav = Navigator.of(context);
      50           2 :     return Consumer<AppData>(builder: (context, appState, _) {
      51           1 :       return Visibility(
      52           4 :         visible: appState.getByUuid(uuid)?.hidden == false,
      53           1 :         child: SwipeActionCell(
      54           2 :           key: ValueKey(key),
      55             :           backgroundColor: Colors.transparent,
      56           1 :           trailingActions: [
      57           1 :             SwipeAction(
      58           1 :               nestedAction: SwipeNestedAction(
      59           1 :                 content: MouseRegion(
      60             :                   cursor: SystemMouseCursors.click,
      61           1 :                   child: Container(
      62           1 :                     height: height,
      63           1 :                     decoration: BoxDecoration(
      64           1 :                       borderRadius: BorderRadius.circular(30),
      65             :                       color: Colors.red,
      66             :                     ),
      67           1 :                     child: OverflowBox(
      68             :                       maxWidth: double.infinity,
      69           1 :                       child: Row(
      70             :                         mainAxisAlignment: MainAxisAlignment.center,
      71           1 :                         children: [
      72             :                           const Icon(Icons.delete, color: Colors.white),
      73           3 :                           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           3 :               content: _getIcon(Icons.delete, Colors.red, Colors.white, AppLocale.labels.deleteTooltip),
      84             :             ),
      85           1 :             SwipeAction(
      86             :               color: Colors.transparent,
      87             :               closeOnTap: true,
      88           0 :               onTap: (_) => nav.pushNamed(routePath!, arguments: {routeArguments.uuid: uuid}),
      89           3 :               content: _getIcon(Icons.edit, Colors.grey, Colors.white, AppLocale.labels.editTooltip),
      90             :             ),
      91             :           ],
      92           1 :           child: child,
      93             :         ),
      94             :       );
      95             :     });
      96             :   }
      97             : }

Generated by: LCOV version 1.14