rustdesk/flutter/lib/desktop/widgets/menu_button.dart

64 lines
1.7 KiB
Dart
Raw Normal View History

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