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/structure/navigation/app_menu.dart'; 5 : import 'package:app_finance/_classes/structure/navigation/app_menu_item.dart'; 6 : import 'package:app_finance/_configs/screen_helper.dart'; 7 : import 'package:app_finance/_configs/theme_helper.dart'; 8 : import 'package:app_finance/_ext/build_context_ext.dart'; 9 : import 'package:app_finance/design/wrapper/text_wrapper.dart'; 10 : import 'package:flutter/material.dart'; 11 : 12 : class MenuWidget extends StatelessWidget { 13 : final int index; 14 : final int selectedIndex; 15 : final Function setState; 16 : final FocusNode focus = FocusNode(); 17 : 18 1 : MenuWidget({ 19 : super.key, 20 : required this.index, 21 : required this.selectedIndex, 22 : required this.setState, 23 : }); 24 : 25 1 : void _navigateToPage(NavigatorState nav, String routeName) { 26 1 : nav.pop(); 27 1 : nav.pushNamed(routeName); 28 : } 29 : 30 0 : void _onHover(bool isHovered) { 31 : if (isHovered) { 32 0 : setState(); 33 : } 34 : } 35 : 36 1 : @override 37 : Widget build(BuildContext context) { 38 1 : final indent = ThemeHelper.getIndent(); 39 1 : final isWide = ScreenHelper.state().isWide; 40 1 : final ColorScheme colorScheme = context.colorScheme; 41 1 : final TextTheme textTheme = context.textTheme; 42 3 : final isSelected = selectedIndex == index; 43 2 : Color color = isSelected ? colorScheme.primary : colorScheme.secondary; 44 2 : AppMenuItem menu = AppMenu.getByIndex(index); 45 1 : NavigatorState nav = Navigator.of(context); 46 : 47 1 : return InkWell( 48 1 : onTap: () { 49 2 : setState(); 50 2 : _navigateToPage(nav, menu.route); 51 : }, 52 3 : focusNode: isSelected && !isWide ? (focus..requestFocus()) : focus, 53 1 : onHover: _onHover, 54 1 : child: Container( 55 1 : padding: EdgeInsets.all(indent), 56 : color: isSelected 57 : ? isWide 58 0 : ? colorScheme.surface 59 2 : : colorScheme.secondary.withOpacity(0.1) 60 : : null, 61 1 : child: Row( 62 : crossAxisAlignment: CrossAxisAlignment.center, 63 1 : children: [ 64 2 : Icon(menu.icon, color: color), 65 1 : Padding( 66 1 : padding: EdgeInsets.only(left: indent), 67 1 : child: TextWrapper( 68 1 : menu.name, 69 2 : style: textTheme.headlineMedium?.copyWith(color: color), 70 : ), 71 : ), 72 : ], 73 : ), 74 : ), 75 : ); 76 : } 77 : }