LCOV - code coverage report
Current view: top level - lib/design/generic - base_header_widget.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 39 49 79.6 %
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/herald/app_design.dart';
       5             : import 'package:app_finance/_classes/herald/app_locale.dart';
       6             : import 'package:app_finance/_classes/herald/app_zoom.dart';
       7             : import 'package:app_finance/_classes/structure/navigation/app_menu.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/wrapper/tap_widget.dart';
      12             : import 'package:app_finance/design/wrapper/text_wrapper.dart';
      13             : import 'package:app_finance/design/button/toolbar_button_widget.dart';
      14             : import 'package:flutter/material.dart';
      15             : import 'package:flutter_currency_picker/flutter_currency_picker.dart';
      16             : import 'package:flutter_grid_layout/flutter_grid_layout.dart';
      17             : import 'package:provider/provider.dart';
      18             : 
      19             : class BaseHeaderWidget extends StatelessWidget {
      20             :   final String? tooltip;
      21             :   final String? route;
      22             :   final String title;
      23             :   final double width;
      24             :   final double total;
      25             :   final bool hasExpand;
      26             :   final bool toExpand;
      27             :   final Function? expand;
      28             : 
      29           3 :   const BaseHeaderWidget({
      30             :     super.key,
      31             :     required this.tooltip,
      32             :     required this.route,
      33             :     required this.title,
      34             :     required this.total,
      35             :     required this.width,
      36             :     this.hasExpand = false,
      37             :     this.toExpand = true,
      38             :     this.expand,
      39           3 :   }) : assert(hasExpand && expand != null || !hasExpand);
      40             : 
      41           3 :   @override
      42             :   Widget build(BuildContext context) {
      43           3 :     double indent = ThemeHelper.getIndent();
      44           3 :     final textTheme = context.textTheme;
      45           3 :     final colorScheme = context.colorScheme;
      46           3 :     final nav = Navigator.of(context);
      47           9 :     final isWide = Provider.of<AppZoom>(context, listen: false).value > 1.5;
      48           3 :     final bnShift = Offset(-4, isWide ? -8 : 0);
      49           6 :     final metrics = AppMenu.metrics(route);
      50           3 :     final subStyle = isWide ? textTheme.bodySmall : textTheme.headlineSmall;
      51           9 :     final subHeight = ThemeHelper.getTextHeight(Text(title, style: subStyle));
      52           3 :     final numStyle = isWide ? textTheme.numberSmall : textTheme.numberLarge;
      53          12 :     final numHeight = ThemeHelper.getTextHeight(Text(total.toString(), style: numStyle));
      54           3 :     return TapWidget(
      55           3 :       tooltip: tooltip,
      56           6 :       route: RouteSettings(name: route),
      57           3 :       child: Container(
      58           6 :         padding: EdgeInsets.all(indent / 2),
      59           6 :         height: numHeight + subHeight + indent,
      60             :         width: double.infinity,
      61           6 :         color: colorScheme.inverseSurface.withOpacity(0.1),
      62           3 :         child: GridContainer(
      63           3 :           alignment: AppDesign.getAlignment<MainAxisAlignment>(),
      64           6 :           rows: [null, ThemeHelper.barHeight, if (hasExpand) ThemeHelper.barHeight],
      65           3 :           columns: [subHeight, null],
      66           3 :           children: [
      67           3 :             GridItem(
      68             :               start: const Size(0, 0),
      69             :               end: const Size(1, 1),
      70           6 :               child: TextWrapper(title, style: subStyle),
      71             :             ),
      72           3 :             GridItem(
      73             :               start: const Size(0, 1),
      74             :               end: const Size(1, 2),
      75           3 :               child: FittedBox(
      76             :                 fit: BoxFit.scaleDown,
      77           3 :                 alignment: AppDesign.isRightToLeft() ? Alignment.centerRight : Alignment.centerLeft,
      78           9 :                 child: TextWrapper(total.toCurrency(withPattern: false), style: numStyle),
      79             :               ),
      80             :             ),
      81           3 :             GridItem(
      82             :               start: const Size(1, 0),
      83             :               end: const Size(2, 2),
      84           3 :               child: ToolbarButtonWidget(
      85           9 :                 borderColor: context.colorScheme.onSecondaryContainer.withOpacity(0.3),
      86             :                 offset: bnShift,
      87             :                 icon: Icons.stacked_bar_chart,
      88           6 :                 color: context.colorScheme.onSecondaryContainer,
      89           6 :                 tooltip: AppLocale.labels.metricsTooltip,
      90           0 :                 onPressed: () => nav.pushNamed(metrics.name!, arguments: metrics.arguments),
      91           9 :                 backgroundColor: context.colorScheme.surface.withOpacity(0.3),
      92             :               ),
      93             :             ),
      94           3 :             if (hasExpand)
      95           0 :               GridItem(
      96             :                 start: const Size(2, 0),
      97             :                 end: const Size(3, 2),
      98           0 :                 child: ToolbarButtonWidget(
      99           0 :                   borderColor: context.colorScheme.onSecondaryContainer.withOpacity(0.3),
     100             :                   offset: bnShift,
     101             :                   selectedIcon: Icons.expand,
     102           0 :                   selectedColor: context.colorScheme.onSecondaryContainer,
     103           0 :                   backgroundColor: context.colorScheme.surface.withOpacity(0.3),
     104             :                   icon: Icons.expand_less,
     105           0 :                   color: context.colorScheme.primary.withOpacity(0.6),
     106           0 :                   tooltip: toExpand ? AppLocale.labels.expand : AppLocale.labels.collapse,
     107           0 :                   onPressed: () => expand!(),
     108           0 :                   isSelected: toExpand,
     109             :                 ),
     110             :               ),
     111             :           ],
     112             :         ),
     113             :       ),
     114             :     );
     115             :   }
     116             : }

Generated by: LCOV version 1.14