From 492bc1525bcd1dc9e972477596ca46a5be6b85a1 Mon Sep 17 00:00:00 2001 From: Kingtous Date: Mon, 24 Oct 2022 16:44:43 +0800 Subject: [PATCH] fix: action button stateful tooltip --- .../lib/desktop/widgets/tabbar_widget.dart | 64 ++++++++++++------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/flutter/lib/desktop/widgets/tabbar_widget.dart b/flutter/lib/desktop/widgets/tabbar_widget.dart index 03a8b6f01..9c88575ec 100644 --- a/flutter/lib/desktop/widgets/tabbar_widget.dart +++ b/flutter/lib/desktop/widgets/tabbar_widget.dart @@ -171,6 +171,7 @@ class DesktopTabController { class TabThemeConf { double iconSize; + TabThemeConf({required this.iconSize}); } @@ -199,6 +200,7 @@ class DesktopTab extends StatelessWidget { final Color? unSelectedTabBackgroundColor; final DesktopTabController controller; + Rx get state => controller.state; final isMaximized = false.obs; final _scrollDebounce = Debouncer(delay: Duration(milliseconds: 50)); @@ -606,7 +608,8 @@ Future closeConfirmDialog() async { setState(() => confirm = v); }, ) - ]), // confirm checkbox + ]), + // confirm checkbox actions: [ TextButton(onPressed: close, child: Text(translate("Cancel"))), 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 IconData icon; final Function() onTap; final bool isClose; final double iconSize; final double boxSize; + const ActionIcon( {Key? key, this.message, @@ -881,31 +885,45 @@ class ActionIcon extends StatelessWidget { this.boxSize = _kTabBarHeight - 1}) : super(key: key); + @override + State createState() => _ActionIconState(); +} + +class _ActionIconState extends State { + var hover = false.obs; + + @override + void initState() { + super.initState(); + hover.value = false; + } + @override Widget build(BuildContext context) { - RxBool hover = false.obs; - return Obx(() => Tooltip( - message: message != null ? translate(message!) : "", - waitDuration: const Duration(seconds: 1), - child: InkWell( - hoverColor: isClose - ? const Color.fromARGB(255, 196, 43, 28) - : MyTheme.tabbar(context).hoverColor, - onHover: (value) => hover.value = value, - onTap: onTap, - child: SizedBox( - height: boxSize, - width: boxSize, - child: Icon( - icon, - color: hover.value && isClose - ? Colors.white - : MyTheme.tabbar(context).unSelectedIconColor, - size: iconSize, - ), + return Tooltip( + message: widget.message != null ? translate(widget.message!) : "", + waitDuration: const Duration(seconds: 1), + child: Obx( + () => InkWell( + hoverColor: widget.isClose + ? const Color.fromARGB(255, 196, 43, 28) + : MyTheme.tabbar(context).hoverColor, + onHover: (value) => hover.value = value, + onTap: widget.onTap, + child: SizedBox( + height: widget.boxSize, + width: widget.boxSize, + child: Icon( + widget.icon, + color: hover.value && widget.isClose + ? Colors.white + : MyTheme.tabbar(context).unSelectedIconColor, + size: widget.iconSize, ), ), - )); + ), + ), + ); } }