| 
									
										
										
										
											2023-02-15 11:40:17 +01:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MenuButton extends StatefulWidget { | 
					
						
							|  |  |  |   final GestureTapCallback? onPressed; | 
					
						
							|  |  |  |   final Color color; | 
					
						
							|  |  |  |   final Color hoverColor; | 
					
						
							|  |  |  |   final Color? splashColor; | 
					
						
							| 
									
										
										
										
											2023-02-17 13:32:17 +08:00
										 |  |  |   final Widget child; | 
					
						
							| 
									
										
										
										
											2023-02-15 13:19:15 +01:00
										 |  |  |   final String? tooltip; | 
					
						
							| 
									
										
										
										
											2023-02-15 11:40:17 +01:00
										 |  |  |   final EdgeInsetsGeometry padding; | 
					
						
							|  |  |  |   final bool enableFeedback; | 
					
						
							|  |  |  |   const MenuButton({ | 
					
						
							|  |  |  |     super.key, | 
					
						
							|  |  |  |     required this.onPressed, | 
					
						
							|  |  |  |     required this.color, | 
					
						
							|  |  |  |     required this.hoverColor, | 
					
						
							| 
									
										
										
										
											2023-02-17 13:32:17 +08:00
										 |  |  |     required this.child, | 
					
						
							| 
									
										
										
										
											2023-02-15 11:40:17 +01:00
										 |  |  |     this.splashColor, | 
					
						
							| 
									
										
										
										
											2023-02-15 13:19:15 +01:00
										 |  |  |     this.tooltip = "", | 
					
						
							| 
									
										
										
										
											2023-02-15 14:14:21 +01:00
										 |  |  |     this.padding = const EdgeInsets.symmetric(horizontal: 3, vertical: 6), | 
					
						
							| 
									
										
										
										
											2023-02-15 11:40:17 +01:00
										 |  |  |     this.enableFeedback = true, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   State<MenuButton> createState() => _MenuButtonState(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _MenuButtonState extends State<MenuButton> { | 
					
						
							|  |  |  |   bool _isHover = false; | 
					
						
							| 
									
										
										
										
											2023-02-22 22:13:21 +01:00
										 |  |  |   final double _borderRadius = 8.0; | 
					
						
							| 
									
										
										
										
											2023-02-15 11:40:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     return Padding( | 
					
						
							|  |  |  |       padding: widget.padding, | 
					
						
							|  |  |  |       child: Tooltip( | 
					
						
							|  |  |  |         message: widget.tooltip, | 
					
						
							|  |  |  |         child: Material( | 
					
						
							|  |  |  |           type: MaterialType.transparency, | 
					
						
							| 
									
										
										
										
											2023-02-25 10:08:34 +01:00
										 |  |  |           child: Container( | 
					
						
							| 
									
										
										
										
											2023-02-15 11:40:17 +01:00
										 |  |  |             decoration: BoxDecoration( | 
					
						
							| 
									
										
										
										
											2023-02-22 22:13:21 +01:00
										 |  |  |               borderRadius: BorderRadius.circular(_borderRadius), | 
					
						
							| 
									
										
										
										
											2023-02-15 11:40:17 +01:00
										 |  |  |               color: _isHover ? widget.hoverColor : widget.color, | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             child: InkWell( | 
					
						
							| 
									
										
										
										
											2023-02-22 22:13:21 +01:00
										 |  |  |               hoverColor: widget.hoverColor, | 
					
						
							| 
									
										
										
										
											2023-02-15 11:40:17 +01:00
										 |  |  |               onHover: (val) { | 
					
						
							|  |  |  |                 setState(() { | 
					
						
							|  |  |  |                   _isHover = val; | 
					
						
							|  |  |  |                 }); | 
					
						
							|  |  |  |               }, | 
					
						
							| 
									
										
										
										
											2023-02-22 22:13:21 +01:00
										 |  |  |               borderRadius: BorderRadius.circular(_borderRadius), | 
					
						
							| 
									
										
										
										
											2023-02-15 11:40:17 +01:00
										 |  |  |               splashColor: widget.splashColor, | 
					
						
							|  |  |  |               enableFeedback: widget.enableFeedback, | 
					
						
							|  |  |  |               onTap: widget.onPressed, | 
					
						
							| 
									
										
										
										
											2023-02-17 13:32:17 +08:00
										 |  |  |               child: widget.child, | 
					
						
							| 
									
										
										
										
											2023-02-15 11:40:17 +01:00
										 |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |