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

Generated by: LCOV version 2.0-1