LCOV - code coverage report
Current view: top level - lib/design/generic - base_widget.dart Coverage Total Hit
Test: lcov.info Lines: 57.5 % 80 46
Test Date: 2026-11-14 15:08:11 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/iterator_controller.dart';
       5              : import 'package:app_finance/_classes/herald/app_design.dart';
       6              : import 'package:app_finance/_classes/storage/app_data.dart';
       7              : import 'package:app_finance/_classes/storage/app_preferences.dart';
       8              : import 'package:app_finance/_configs/custom_text_theme.dart';
       9              : import 'package:app_finance/_configs/theme_helper.dart';
      10              : import 'package:app_finance/_ext/build_context_ext.dart';
      11              : import 'package:app_finance/design/generic/base_header_widget.dart';
      12              : import 'package:app_finance/design/generic/base_line_widget.dart';
      13              : import 'package:app_finance/design/generic/base_list_infinite_widget.dart';
      14              : import 'package:app_finance/design/generic/base_list_limited_widget.dart';
      15              : import 'package:app_finance/design/generic/base_swipe_widget.dart';
      16              : import 'package:material_ui/material_ui.dart';
      17              : import 'package:flutter_currency_picker/flutter_currency_picker.dart';
      18              : 
      19              : class BaseWidget extends StatelessWidget {
      20              :   final EdgeInsetsGeometry margin;
      21              :   final String title;
      22              :   final double width;
      23              :   final int? limit;
      24              :   final AppDataGetter state;
      25              :   final String? tooltip;
      26              :   final String? route;
      27              :   final String routeList;
      28              :   final bool hasExpand;
      29              :   final String? toExpand;
      30              :   final Function? callback;
      31              : 
      32            1 :   const BaseWidget({
      33              :     super.key,
      34              :     required this.margin,
      35              :     required this.title,
      36              :     required this.state,
      37              :     required this.width,
      38              :     this.tooltip,
      39              :     this.limit,
      40              :     this.route,
      41              :     this.routeList = '',
      42              :     this.hasExpand = false,
      43              :     this.toExpand = '',
      44              :     this.callback,
      45              :   });
      46              : 
      47            1 :   Widget buildListWidget(item, BuildContext context) {
      48            1 :     return BaseSwipeWidget(
      49            2 :       routePath: routeList.replaceAll('/view', '/edit'),
      50            1 :       uuid: item.uuid,
      51            1 :       child: BaseLineWidget(
      52            1 :         uuid: item.uuid ?? '',
      53            1 :         title: item.title,
      54            1 :         description: item.description ?? '',
      55            1 :         details: item.detailsFormatted,
      56            1 :         progress: item.progress,
      57            1 :         color: item.color ?? Colors.transparent,
      58            1 :         icon: item.icon ?? Icons.radio_button_unchecked_sharp,
      59            1 :         hidden: item.hidden,
      60            1 :         skip: item.skip,
      61            1 :         width: width,
      62            1 :         route: routeList,
      63              :       ),
      64              :     );
      65              :   }
      66              : 
      67            0 :   void _expand() {
      68            0 :     String outcome = toExpand == title ? '' : title;
      69            0 :     AppPreferences.set(AppPreferences.prefExpand, outcome);
      70            0 :     if (callback != null) {
      71            0 :       callback!(outcome);
      72              :     }
      73              :   }
      74              : 
      75            1 :   @override
      76              :   Widget build(BuildContext context) {
      77            1 :     if (!hasExpand || (toExpand ?? '') == '' || toExpand == title) {
      78            1 :       return buildFull(context);
      79              :     }
      80            0 :     return buildCollapsed(context);
      81              :   }
      82              : 
      83            0 :   Widget buildMinimized(BuildContext context) {
      84            0 :     return Container(
      85            0 :       margin: EdgeInsets.only(top: ThemeHelper.getIndent(3)),
      86              :       alignment: Alignment.center,
      87            0 :       decoration: BoxDecoration(
      88              :         shape: BoxShape.circle,
      89            0 :         color: context.colorScheme.inverseSurface.withValues(alpha: 0.1),
      90              :       ),
      91            0 :       height: ThemeHelper.getHeight(context),
      92            0 :       child: Column(
      93            0 :         children: [
      94            0 :           SizedBox(height: ThemeHelper.getHeight(context) / 2 - 2 * ThemeHelper.getTextHeight(Text(title))),
      95            0 :           Text(title),
      96              :           ThemeHelper.hIndent,
      97            0 :           Text(
      98            0 :             state.total.toCurrency(withPattern: false),
      99            0 :             style: context.textTheme.numberMedium,
     100              :           ),
     101              :         ],
     102              :       ),
     103              :     );
     104              :   }
     105              : 
     106            0 :   Widget buildCollapsed(BuildContext context) {
     107            0 :     return Container(
     108            0 :       margin: margin,
     109            0 :       child: BaseHeaderWidget(
     110            0 :         route: route,
     111            0 :         width: width,
     112            0 :         total: state.total,
     113            0 :         title: title,
     114            0 :         tooltip: tooltip,
     115            0 :         hasExpand: hasExpand,
     116              :         toExpand: true,
     117            0 :         expand: _expand,
     118              :       ),
     119              :     );
     120              :   }
     121              : 
     122            1 :   Widget buildFull(BuildContext context) {
     123            1 :     return Expanded(
     124            1 :       child: Container(
     125            1 :         margin: margin,
     126            1 :         child: Column(
     127            1 :           crossAxisAlignment: AppDesign.getAlignment(),
     128            1 :           children: [
     129            1 :             BaseHeaderWidget(
     130            1 :               route: route,
     131            1 :               width: width,
     132            1 :               total: state.total,
     133            1 :               title: title,
     134            1 :               tooltip: tooltip,
     135            1 :               hasExpand: hasExpand,
     136            3 :               hasMetrics: limit != null && limit! > 0,
     137            2 :               toExpand: (toExpand ?? '') == '' || toExpand != title,
     138            1 :               expand: _expand,
     139              :             ),
     140            1 :             Expanded(
     141            1 :               child: limit != null
     142            1 :                   ? BaseListLimitedWidget(
     143            1 :                       route: route,
     144            1 :                       state: state.list,
     145            1 :                       limit: limit,
     146            1 :                       routeList: routeList,
     147            1 :                       width: width,
     148            1 :                       buildListWidget: buildListWidget,
     149              :                     )
     150            0 :                   : BaseListInfiniteWidget(
     151            0 :                       stream: state.stream as IteratorReverseController,
     152            0 :                       width: width,
     153            0 :                       buildListWidget: buildListWidget,
     154              :                     ),
     155              :             ),
     156              :           ],
     157              :         ),
     158              :       ),
     159              :     );
     160              :   }
     161              : }
        

Generated by: LCOV version 2.0-1