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/_classes/structure/navigation/app_route.dart';
6 : import 'package:app_finance/_ext/build_context_ext.dart';
7 : import 'package:material_ui/material_ui.dart';
8 : import 'package:flutter/semantics.dart';
9 :
10 : class TapWidget extends StatelessWidget {
11 : final Widget child;
12 : final String? tooltip;
13 : final RouteSettings? route;
14 : final Function? onTap;
15 : final Function(bool)? onFocusChange;
16 : final bool toWrap;
17 :
18 1 : const TapWidget({
19 : super.key,
20 : required this.child,
21 : this.tooltip,
22 : this.route,
23 : this.onTap,
24 : this.onFocusChange,
25 : this.toWrap = true,
26 : });
27 :
28 1 : @override
29 : Widget build(context) {
30 1 : if (!toWrap) {
31 1 : return child;
32 : }
33 1 : NavigatorState nav = Navigator.of(context);
34 1 : return Semantics(
35 : container: true,
36 2 : attributedHint: AttributedString(tooltip ?? AppLocale.labels.tapToOpen),
37 1 : child: Tooltip(
38 1 : message: tooltip ?? AppLocale.labels.homeTooltip,
39 4 : child: onTap != null || route?.name != ''
40 1 : ? InkWell(
41 3 : focusColor: context.colorScheme.onSurface.withValues(alpha: 0.08),
42 3 : hoverColor: context.colorScheme.onSurface.withValues(alpha: 0.04),
43 1 : onFocusChange: onFocusChange,
44 1 : onTap: () {
45 1 : if (onTap != null) {
46 2 : onTap!();
47 0 : } else if (route?.name != '') {
48 0 : nav.pushNamed(route?.name ?? AppRoute.homeRoute, arguments: route?.arguments);
49 : }
50 : },
51 1 : child: child,
52 : )
53 1 : : child,
54 : ),
55 : );
56 : }
57 : }
|