LCOV - code coverage report
Current view: top level - lib/design/button - full_sized_button_widget.dart Coverage Total Hit
Test: lcov.info Lines: 84.1 % 44 37
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/focus_controller.dart';
       5              : import 'package:app_finance/_configs/screen_helper.dart';
       6              : import 'package:app_finance/_configs/theme_helper.dart';
       7              : import 'package:app_finance/_ext/build_context_ext.dart';
       8              : import 'package:app_finance/design/wrapper/text_wrapper.dart';
       9              : import 'package:material_ui/material_ui.dart';
      10              : import 'package:flutter/semantics.dart';
      11              : import 'package:provider/provider.dart';
      12              : 
      13              : typedef OnPressedFunction = void Function();
      14              : 
      15              : class FullSizedButtonWidget extends StatelessWidget {
      16              :   final OnPressedFunction onPressed;
      17              :   final String title;
      18              :   final IconData icon;
      19              :   final BoxConstraints? constraints;
      20              :   final FocusController? controller;
      21              :   late final String heroTag;
      22              : 
      23            4 :   FullSizedButtonWidget({
      24              :     super.key,
      25              :     required this.onPressed,
      26              :     required this.title,
      27              :     required this.icon,
      28              :     this.constraints,
      29              :     this.controller,
      30            8 :   }) : heroTag = 'fz_button_${UniqueKey()}';
      31              : 
      32            4 :   @override
      33              :   Widget build(BuildContext context) {
      34            8 :     final isBottom = constraints != null ? ThemeHelper.isNavBottom(constraints!) : false;
      35            4 :     final bool isKeyboardVisible = ThemeHelper.isKeyboardVisible(context) || isBottom;
      36            4 :     final colorScheme = context.colorScheme;
      37            4 :     final indent = ThemeHelper.getIndent(4);
      38           12 :     final width = constraints != null ? constraints!.maxWidth - indent - 2 : double.infinity;
      39            4 :     final isWide = ScreenHelper.state().isWide;
      40            4 :     return ChangeNotifierProvider(
      41            8 :       create: (context) => _HoverModel(),
      42            4 :       child: Container(
      43            0 :         margin: isWide ? EdgeInsets.only(left: ThemeHelper.menuWidth + indent) : EdgeInsets.zero,
      44              :         width: isKeyboardVisible ? null : width,
      45            8 :         child: Consumer<_HoverModel>(builder: (context, hoverModel, _) {
      46           12 :           final color = context.textTheme.bodyLarge?.color;
      47            4 :           return MouseRegion(
      48            0 :             onEnter: (_) => hoverModel.setHover(true),
      49            0 :             onExit: (_) => hoverModel.setHover(false),
      50            4 :             child: Semantics(
      51            8 :               attributedLabel: AttributedString(title),
      52              :               button: true,
      53            4 :               child: FloatingActionButton(
      54            4 :                 heroTag: heroTag,
      55            4 :                 onPressed: onPressed,
      56            4 :                 hoverColor: colorScheme.primary,
      57            8 :                 focusColor: colorScheme.primary.withValues(alpha: 0.8),
      58            4 :                 tooltip: title,
      59            6 :                 focusNode: controller?.last(this),
      60            4 :                 child: Row(
      61              :                   mainAxisAlignment: MainAxisAlignment.center,
      62            4 :                   children: [
      63            4 :                     Icon(
      64            4 :                       icon,
      65            4 :                       semanticLabel: title,
      66              :                       size: 32,
      67            4 :                       color: hoverModel.isHovered ? colorScheme.onPrimary : color,
      68              :                     ),
      69              :                     if (!isKeyboardVisible)
      70            2 :                       Container(
      71            4 :                         padding: EdgeInsets.only(left: ThemeHelper.getIndent()),
      72            4 :                         constraints: BoxConstraints(maxWidth: width - 34),
      73            2 :                         child: TextWrapper(
      74            2 :                           title,
      75            4 :                           style: context.textTheme.bodyLarge
      76            4 :                               ?.copyWith(color: hoverModel.isHovered ? colorScheme.onPrimary : color),
      77              :                         ),
      78              :                       ),
      79              :                   ],
      80              :                 ),
      81              :               ),
      82              :             ),
      83              :           );
      84              :         }),
      85              :       ),
      86              :     );
      87              :   }
      88              : }
      89              : 
      90              : class _HoverModel extends ChangeNotifier {
      91              :   bool isHovered = false;
      92              : 
      93            0 :   void setHover(bool value) {
      94            0 :     if (isHovered != value) {
      95            0 :       isHovered = value;
      96            0 :       notifyListeners();
      97              :     }
      98              :   }
      99              : }
        

Generated by: LCOV version 2.0-1