fix: action button stateful tooltip

This commit is contained in:
Kingtous 2022-10-24 16:44:43 +08:00
parent 30ddc95c6b
commit 492bc1525b

View File

@ -171,6 +171,7 @@ class DesktopTabController {
class TabThemeConf { class TabThemeConf {
double iconSize; double iconSize;
TabThemeConf({required this.iconSize}); TabThemeConf({required this.iconSize});
} }
@ -199,6 +200,7 @@ class DesktopTab extends StatelessWidget {
final Color? unSelectedTabBackgroundColor; final Color? unSelectedTabBackgroundColor;
final DesktopTabController controller; final DesktopTabController controller;
Rx<DesktopTabState> get state => controller.state; Rx<DesktopTabState> get state => controller.state;
final isMaximized = false.obs; final isMaximized = false.obs;
final _scrollDebounce = Debouncer(delay: Duration(milliseconds: 50)); final _scrollDebounce = Debouncer(delay: Duration(milliseconds: 50));
@ -606,7 +608,8 @@ Future<bool> closeConfirmDialog() async {
setState(() => confirm = v); setState(() => confirm = v);
}, },
) )
]), // confirm checkbox ]),
// confirm checkbox
actions: [ actions: [
TextButton(onPressed: close, child: Text(translate("Cancel"))), TextButton(onPressed: close, child: Text(translate("Cancel"))),
ElevatedButton(onPressed: submit, child: Text(translate("OK"))), ElevatedButton(onPressed: submit, child: Text(translate("OK"))),
@ -864,13 +867,14 @@ class _CloseButton extends StatelessWidget {
} }
} }
class ActionIcon extends StatelessWidget { class ActionIcon extends StatefulWidget {
final String? message; final String? message;
final IconData icon; final IconData icon;
final Function() onTap; final Function() onTap;
final bool isClose; final bool isClose;
final double iconSize; final double iconSize;
final double boxSize; final double boxSize;
const ActionIcon( const ActionIcon(
{Key? key, {Key? key,
this.message, this.message,
@ -881,31 +885,45 @@ class ActionIcon extends StatelessWidget {
this.boxSize = _kTabBarHeight - 1}) this.boxSize = _kTabBarHeight - 1})
: super(key: key); : super(key: key);
@override
State<ActionIcon> createState() => _ActionIconState();
}
class _ActionIconState extends State<ActionIcon> {
var hover = false.obs;
@override
void initState() {
super.initState();
hover.value = false;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
RxBool hover = false.obs; return Tooltip(
return Obx(() => Tooltip( message: widget.message != null ? translate(widget.message!) : "",
message: message != null ? translate(message!) : "", waitDuration: const Duration(seconds: 1),
waitDuration: const Duration(seconds: 1), child: Obx(
child: InkWell( () => InkWell(
hoverColor: isClose hoverColor: widget.isClose
? const Color.fromARGB(255, 196, 43, 28) ? const Color.fromARGB(255, 196, 43, 28)
: MyTheme.tabbar(context).hoverColor, : MyTheme.tabbar(context).hoverColor,
onHover: (value) => hover.value = value, onHover: (value) => hover.value = value,
onTap: onTap, onTap: widget.onTap,
child: SizedBox( child: SizedBox(
height: boxSize, height: widget.boxSize,
width: boxSize, width: widget.boxSize,
child: Icon( child: Icon(
icon, widget.icon,
color: hover.value && isClose color: hover.value && widget.isClose
? Colors.white ? Colors.white
: MyTheme.tabbar(context).unSelectedIconColor, : MyTheme.tabbar(context).unSelectedIconColor,
size: iconSize, size: widget.iconSize,
),
), ),
), ),
)); ),
),
);
} }
} }