LCOV - code coverage report
Current view: top level - lib/design/button - toolbar_button_widget.dart Coverage Total Hit
Test: lcov.info Lines: 59.6 % 52 31
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/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:material_ui/material_ui.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              :   final double? maxWidth;
      27              : 
      28            6 :   const ToolbarButtonWidget({
      29              :     super.key,
      30              :     required this.onPressed,
      31              :     required this.tooltip,
      32              :     required this.icon,
      33              :     this.color,
      34              :     this.selectedIcon,
      35              :     this.selectedColor,
      36              :     this.semanticLabel,
      37              :     this.isSelected,
      38              :     this.borderColor,
      39              :     this.backgroundColor,
      40              :     this.offset,
      41              :     this.maxWidth,
      42              :     this.isWide = false,
      43              :   });
      44              : 
      45            6 :   @override
      46            6 :   ToolbarButtonWidgetState createState() => ToolbarButtonWidgetState();
      47              : }
      48              : 
      49              : class ToolbarButtonWidgetState extends State<ToolbarButtonWidget> {
      50              :   late Color initColor;
      51           12 :   late Color color = _getColor();
      52              :   bool isHover = false;
      53              : 
      54            6 :   Color _getColor() {
      55           12 :     if (widget.color != null) {
      56           12 :       return widget.color!;
      57              :     }
      58           12 :     return widget.isWide ? context.colorScheme.onSurface : Colors.white70;
      59              :   }
      60              : 
      61            0 :   _onEnter(_) => setState(() {
      62            0 :         color = Colors.white54;
      63            0 :         isHover = true;
      64              :       });
      65              : 
      66            0 :   _onExit(_) => setState(() {
      67            0 :         color = _getColor();
      68            0 :         isHover = false;
      69              :       });
      70              : 
      71            6 :   @override
      72              :   Widget build(BuildContext context) {
      73            6 :     final indent = ThemeHelper.getIndent();
      74           36 :     initColor = widget.backgroundColor ?? context.colorScheme.surface.withValues(alpha: 0.1);
      75           12 :     final borderColor = widget.isWide ? context.colorScheme.onSurface : Colors.white30;
      76            6 :     return Semantics(
      77           18 :       attributedHint: AttributedString(AppLocale.labels.typeButton),
      78           30 :       attributedLabel: AttributedString(widget.semanticLabel ?? widget.tooltip),
      79            6 :       child: MouseRegion(
      80            6 :         onEnter: _onEnter,
      81            6 :         onExit: _onExit,
      82            6 :         child: Container(
      83              :           margin: const EdgeInsets.all(2.0),
      84              :           padding: const EdgeInsets.all(1.0),
      85              :           height: 42,
      86            6 :           decoration: BoxDecoration(
      87              :             shape: BoxShape.rectangle,
      88           12 :             color: isHover ? Colors.black54 : initColor,
      89           18 :             border: Border.all(color: widget.borderColor ?? borderColor, width: 1),
      90              :           ),
      91            6 :           child: Material(
      92              :             elevation: 0,
      93              :             color: Colors.transparent,
      94              :             borderRadius: BorderRadius.zero,
      95            6 :             child: Center(
      96           12 :               child: widget.isWide
      97            0 :                   ? InkWell(
      98            0 :                       onTap: widget.onPressed,
      99            0 :                       child: Row(
     100            0 :                         children: [
     101            0 :                           Icon(widget.icon, color: color),
     102            0 :                           Container(
     103            0 :                             width: widget.maxWidth != null ? widget.maxWidth! - 2 * indent : null,
     104            0 :                             padding: EdgeInsets.fromLTRB(indent, indent, indent, 0),
     105            0 :                             child: TextWrapper(
     106            0 :                               widget.tooltip,
     107            0 :                               maxWidth: widget.maxWidth != null ? widget.maxWidth! - 3 * indent : null,
     108            0 :                               style: context.textTheme.headlineSmall?.copyWith(color: color),
     109              :                             ),
     110              :                           ),
     111              :                         ],
     112              :                       ),
     113              :                     )
     114            6 :                   : IconButton(
     115           12 :                       tooltip: widget.tooltip,
     116           12 :                       onPressed: widget.onPressed,
     117           12 :                       isSelected: widget.isSelected,
     118              :                       hoverColor: Colors.transparent,
     119           24 :                       icon: Icon(widget.icon, color: color),
     120           12 :                       selectedIcon: widget.selectedIcon != null
     121            0 :                           ? Icon(
     122            0 :                               widget.selectedIcon,
     123            0 :                               color: isHover ? color : widget.selectedColor,
     124              :                             )
     125              :                           : null,
     126              :                     ),
     127              :             ),
     128              :           ),
     129              :         ),
     130              :       ),
     131              :     );
     132              :   }
     133              : }
        

Generated by: LCOV version 2.0-1