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: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/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            6 :   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            2 :   Widget buildListWidget(item, BuildContext context) {
      48            2 :     return BaseSwipeWidget(
      49            4 :       routePath: routeList.replaceAll('/view', '/edit'),
      50            2 :       uuid: item.uuid,
      51            2 :       child: BaseLineWidget(
      52            2 :         uuid: item.uuid ?? '',
      53            2 :         title: item.title,
      54            2 :         description: item.description ?? '',
      55            2 :         details: item.detailsFormatted,
      56            2 :         progress: item.progress,
      57            2 :         color: item.color ?? Colors.transparent,
      58            2 :         icon: item.icon ?? Icons.radio_button_unchecked_sharp,
      59            2 :         hidden: item.hidden,
      60            2 :         skip: item.skip,
      61            2 :         width: width,
      62            2 :         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            6 :   @override
      76              :   Widget build(BuildContext context) {
      77            6 :     if (!hasExpand || (toExpand ?? '') == '' || toExpand == title) {
      78            6 :       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            6 :   Widget buildFull(BuildContext context) {
     123            6 :     return Expanded(
     124            6 :       child: Container(
     125            6 :         margin: margin,
     126            6 :         child: Column(
     127            6 :           crossAxisAlignment: AppDesign.getAlignment(),
     128            6 :           children: [
     129            6 :             BaseHeaderWidget(
     130            6 :               route: route,
     131            6 :               width: width,
     132            6 :               total: state.total,
     133            6 :               title: title,
     134            6 :               tooltip: tooltip,
     135            6 :               hasExpand: hasExpand,
     136           18 :               hasMetrics: limit != null && limit! > 0,
     137           12 :               toExpand: (toExpand ?? '') == '' || toExpand != title,
     138            6 :               expand: _expand,
     139              :             ),
     140            6 :             Expanded(
     141            6 :               child: limit != null
     142            6 :                   ? BaseListLimitedWidget(
     143            6 :                       route: route,
     144            6 :                       state: state.list,
     145            6 :                       limit: limit,
     146            6 :                       routeList: routeList,
     147            6 :                       width: width,
     148            6 :                       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