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_locale.dart';
5 : import 'package:app_finance/_configs/theme_helper.dart';
6 : import 'package:app_finance/_ext/build_context_ext.dart';
7 : import 'package:app_finance/design/wrapper/text_wrapper.dart';
8 : import 'package:flutter/material.dart';
9 : import 'package:flutter/semantics.dart';
10 :
11 : typedef FnCall = void Function();
12 :
13 : class ToolbarButtonWidget extends StatefulWidget {
14 : final Color color;
15 : final Color? borderColor;
16 : final Color? backgroundColor;
17 : final Color? selectedColor;
18 : final Offset? offset;
19 : final bool isWide;
20 : final FnCall onPressed;
21 : final String tooltip;
22 : final String? semanticLabel;
23 : final IconData icon;
24 : final IconData? selectedIcon;
25 : final bool? isSelected;
26 :
27 1 : const ToolbarButtonWidget({
28 : super.key,
29 : required this.onPressed,
30 : required this.tooltip,
31 : required this.color,
32 : required this.icon,
33 : this.selectedIcon,
34 : this.selectedColor,
35 : this.semanticLabel,
36 : this.isSelected,
37 : this.borderColor,
38 : this.backgroundColor,
39 : this.offset,
40 : this.isWide = false,
41 : });
42 :
43 1 : @override
44 1 : ToolbarButtonWidgetState createState() => ToolbarButtonWidgetState();
45 : }
46 :
47 : class ToolbarButtonWidgetState extends State<ToolbarButtonWidget> {
48 : late Color initColor;
49 3 : late Color color = widget.color;
50 : bool isHover = false;
51 :
52 0 : _onEnter(_) => setState(() {
53 0 : color = Colors.white54;
54 0 : isHover = true;
55 : });
56 :
57 0 : _onExit(_) => setState(() {
58 0 : color = widget.color;
59 0 : isHover = false;
60 : });
61 :
62 1 : @override
63 : Widget build(BuildContext context) {
64 1 : final indent = ThemeHelper.getIndent();
65 6 : initColor = widget.backgroundColor ?? context.colorScheme.surface.withOpacity(0.1);
66 1 : return Semantics(
67 3 : attributedHint: AttributedString(AppLocale.labels.typeButton),
68 5 : attributedLabel: AttributedString(widget.semanticLabel ?? widget.tooltip),
69 1 : child: MouseRegion(
70 1 : onEnter: _onEnter,
71 1 : onExit: _onExit,
72 1 : child: Container(
73 : margin: const EdgeInsets.all(2.0),
74 : padding: const EdgeInsets.all(1.0),
75 : height: 42,
76 1 : decoration: BoxDecoration(
77 : shape: BoxShape.rectangle,
78 2 : color: isHover ? Colors.black54 : initColor,
79 3 : border: Border.all(color: widget.borderColor ?? Colors.white30, width: 1),
80 : ),
81 1 : child: Material(
82 : elevation: 0,
83 : color: Colors.transparent,
84 : borderRadius: BorderRadius.zero,
85 1 : child: Center(
86 2 : child: widget.isWide
87 0 : ? InkWell(
88 0 : onTap: widget.onPressed,
89 0 : child: Row(
90 0 : children: [
91 0 : Icon(widget.icon, color: color),
92 0 : Padding(
93 0 : padding: EdgeInsets.fromLTRB(indent, indent, indent, 0),
94 0 : child: TextWrapper(
95 0 : widget.tooltip,
96 0 : style: context.textTheme.headlineSmall?.copyWith(color: color),
97 : ),
98 : ),
99 : ],
100 : ),
101 : )
102 1 : : IconButton(
103 2 : tooltip: widget.tooltip,
104 2 : onPressed: widget.onPressed,
105 2 : isSelected: widget.isSelected,
106 : hoverColor: Colors.transparent,
107 4 : icon: Icon(widget.icon, color: color),
108 2 : selectedIcon: widget.selectedIcon != null
109 0 : ? Icon(
110 0 : widget.selectedIcon,
111 0 : color: isHover ? color : widget.selectedColor,
112 : )
113 : : null,
114 : ),
115 : ),
116 : ),
117 : ),
118 : ),
119 : );
120 : }
121 : }
|