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 1 : 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 1 : }) : assert(hasExpand && expand != null || !hasExpand);
40 :
41 1 : @override
42 : Widget build(BuildContext context) {
43 1 : double indent = ThemeHelper.getIndent();
44 1 : final textTheme = context.textTheme;
45 1 : final colorScheme = context.colorScheme;
46 1 : final nav = Navigator.of(context);
47 3 : final isWide = Provider.of<AppZoom>(context, listen: false).value > 1.5;
48 1 : final bnShift = Offset(-4, isWide ? -8 : 0);
49 2 : final metrics = AppMenu.metrics(route);
50 1 : final subStyle = isWide ? textTheme.bodySmall : textTheme.headlineSmall;
51 3 : final subHeight = ThemeHelper.getTextHeight(Text(title, style: subStyle));
52 1 : final numStyle = isWide ? textTheme.numberSmall : textTheme.numberLarge;
53 4 : final numHeight = ThemeHelper.getTextHeight(Text(total.toString(), style: numStyle));
54 1 : return TapWidget(
55 1 : tooltip: tooltip,
56 2 : route: RouteSettings(name: route),
57 1 : child: Container(
58 2 : padding: EdgeInsets.all(indent / 2),
59 2 : height: numHeight + subHeight + indent,
60 : width: double.infinity,
61 2 : color: colorScheme.inverseSurface.withOpacity(0.1),
62 1 : child: GridContainer(
63 1 : alignment: AppDesign.getAlignment<MainAxisAlignment>(),
64 2 : rows: [null, ThemeHelper.barHeight, if (hasExpand) ThemeHelper.barHeight],
65 1 : columns: [subHeight, null],
66 1 : children: [
67 1 : GridItem(
68 : start: const Size(0, 0),
69 : end: const Size(1, 1),
70 2 : child: TextWrapper(title, style: subStyle),
71 : ),
72 1 : GridItem(
73 : start: const Size(0, 1),
74 : end: const Size(1, 2),
75 1 : child: FittedBox(
76 : fit: BoxFit.scaleDown,
77 1 : alignment: AppDesign.isRightToLeft() ? Alignment.centerRight : Alignment.centerLeft,
78 3 : child: TextWrapper(total.toCurrency(withPattern: false), style: numStyle),
79 : ),
80 : ),
81 1 : GridItem(
82 : start: const Size(1, 0),
83 : end: const Size(2, 2),
84 1 : child: ToolbarButtonWidget(
85 3 : borderColor: context.colorScheme.onSecondaryContainer.withOpacity(0.3),
86 : offset: bnShift,
87 : icon: Icons.stacked_bar_chart,
88 2 : color: context.colorScheme.onSecondaryContainer,
89 2 : tooltip: AppLocale.labels.metricsTooltip,
90 0 : onPressed: () => nav.pushNamed(metrics.name!, arguments: metrics.arguments),
91 3 : backgroundColor: context.colorScheme.surface.withOpacity(0.3),
92 : ),
93 : ),
94 1 : 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 : }
|