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 : final bool isDisabled;
22 : late final String heroTag;
23 :
24 1 : FullSizedButtonWidget({
25 : super.key,
26 : required this.onPressed,
27 : required this.title,
28 : required this.icon,
29 : this.constraints,
30 : this.controller,
31 : this.isDisabled = false,
32 2 : }) : heroTag = 'fz_button_${UniqueKey()}';
33 :
34 1 : @override
35 : Widget build(BuildContext context) {
36 3 : final isBottom = constraints != null ? ThemeHelper.isNavBottom(constraints!) : false;
37 1 : final bool isKeyboardVisible = ThemeHelper.isKeyboardVisible(context) || isBottom;
38 1 : final colorScheme = context.colorScheme;
39 1 : final indent = ThemeHelper.getIndent(4);
40 5 : final width = constraints != null ? constraints!.maxWidth - indent - 2 : double.infinity;
41 1 : final isWide = ScreenHelper.state().isWide;
42 1 : return ChangeNotifierProvider(
43 2 : create: (context) => _HoverModel(),
44 1 : child: Container(
45 0 : margin: isWide ? EdgeInsets.only(left: ThemeHelper.menuWidth + indent) : EdgeInsets.zero,
46 : width: isKeyboardVisible ? null : width,
47 2 : child: Consumer<_HoverModel>(builder: (context, hoverModel, _) {
48 3 : final color = context.textTheme.bodyLarge?.color;
49 1 : return MouseRegion(
50 0 : onEnter: (_) => hoverModel.setHover(true),
51 0 : onExit: (_) => hoverModel.setHover(false),
52 1 : child: Semantics(
53 2 : attributedLabel: AttributedString(title),
54 : button: true,
55 1 : child: FloatingActionButton(
56 1 : heroTag: heroTag,
57 2 : onPressed: isDisabled ? null : onPressed,
58 1 : hoverColor: colorScheme.primary,
59 2 : focusColor: colorScheme.primary.withValues(alpha: 0.8),
60 1 : tooltip: title,
61 2 : focusNode: controller?.last(this),
62 1 : child: Row(
63 : mainAxisAlignment: MainAxisAlignment.center,
64 1 : children: [
65 1 : Icon(
66 1 : icon,
67 1 : semanticLabel: title,
68 : size: 32,
69 1 : color: hoverModel.isHovered ? colorScheme.onPrimary : color,
70 : ),
71 : if (!isKeyboardVisible)
72 0 : Container(
73 0 : padding: EdgeInsets.only(left: ThemeHelper.getIndent()),
74 0 : constraints: BoxConstraints(maxWidth: width - 34),
75 0 : child: TextWrapper(
76 0 : title,
77 0 : style: context.textTheme.bodyLarge
78 0 : ?.copyWith(color: hoverModel.isHovered ? colorScheme.onPrimary : color),
79 : ),
80 : ),
81 : ],
82 : ),
83 : ),
84 : ),
85 : );
86 : }),
87 : ),
88 : );
89 : }
90 : }
91 :
92 : class _HoverModel extends ChangeNotifier {
93 : bool isHovered = false;
94 :
95 0 : void setHover(bool value) {
96 0 : if (isHovered != value) {
97 0 : isHovered = value;
98 0 : notifyListeners();
99 : }
100 : }
101 : }
|