add hover detector to wrap a hovering widget
This commit is contained in:
parent
9373df296c
commit
d2fa3022d7
25
lib/hover_detector.dart
Normal file
25
lib/hover_detector.dart
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class HoverDetector extends StatefulWidget {
|
||||||
|
const HoverDetector(
|
||||||
|
{Key? key, required this.defaultChild, required this.hoverChild})
|
||||||
|
: super(key: key);
|
||||||
|
final Widget defaultChild;
|
||||||
|
final Widget hoverChild;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<HoverDetector> createState() => _HoverDetectorState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HoverDetectorState extends State<HoverDetector> {
|
||||||
|
bool amIHovering = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MouseRegion(
|
||||||
|
child: amIHovering ? widget.hoverChild : widget.defaultChild,
|
||||||
|
onEnter: (PointerEvent details) => setState(() => amIHovering = true),
|
||||||
|
onExit: (PointerEvent details) => setState(() => amIHovering = false),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user