12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import 'package:fis_ui/define.dart';
- import 'package:fis_ui/widgets/container/container.dart';
- import 'package:fis_ui/widgets/core.dart';
- import 'package:fis_ui/widgets/gesture/mouse_region.dart';
- import 'package:flutter/material.dart';
- /// 悬浮高亮组件容器
- class FHoverHighlightContainer extends FStatefulWidget {
- /// 子组件
- final FWidget child;
- /// 高亮颜色
- final Color? highlightColor;
- /// 装饰
- final BoxDecoration? decoration;
- FHoverHighlightContainer({
- required this.child,
- this.highlightColor,
- this.decoration,
- super.key,
- });
- @override
- _HoverHighlightState createState() => _HoverHighlightState();
- }
- class _HoverHighlightState extends FState<FHoverHighlightContainer> {
- bool _isHovered = false;
- @override
- FWidget build(BuildContext context) {
- final highLightColor =
- widget.highlightColor ?? Theme.of(context).highlightColor;
- final color = _isHovered ? highLightColor : Colors.transparent;
- final BoxDecoration decoration;
- if (widget.decoration != null) {
- decoration = widget.decoration!.copyWith(color: color);
- } else {
- decoration = BoxDecoration(color: color);
- }
- return FMouseRegion(
- onEnter: (_) => setState(() => _isHovered = true),
- onExit: (_) => setState(() => _isHovered = false),
- child: FContainer(
- decoration: decoration,
- child: widget.child,
- ),
- );
- }
- }
|