diff --git a/lib/common/utils.dart b/lib/common/utils.dart index b8c8869b..9e5864f9 100644 --- a/lib/common/utils.dart +++ b/lib/common/utils.dart @@ -16,6 +16,7 @@ import 'dart:math' as math; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/scheduler.dart'; import 'package:tuple/tuple.dart'; import 'package:url_launcher/url_launcher.dart' as url_launcher; import 'package:url_launcher/url_launcher_string.dart'; @@ -221,3 +222,11 @@ T stampDateTime(T t, {required T max, required T min}) { t = t < min ? min : t; return t; } + +Future dismissAllToolTips() async { + final result = Tooltip.dismissAllToolTips(); + await Future.delayed(result + ? const Duration(milliseconds: 150) * timeDilation + : Duration.zero); + return result; +} diff --git a/lib/component/widgets/page_back_button.dart b/lib/component/widgets/page_back_button.dart index e095962f..7803c91b 100644 --- a/lib/component/widgets/page_back_button.dart +++ b/lib/component/widgets/page_back_button.dart @@ -14,6 +14,8 @@ import 'package:flutter/material.dart'; +import '../../common/utils.dart'; + enum PageBackReason { back, close } class PageBackButton extends StatelessWidget { @@ -28,16 +30,23 @@ class PageBackButton extends StatelessWidget { this.onPressed, }); + void _onPressedCallback(BuildContext context) => + dismissAllToolTips().then((_) => Navigator.maybePop(context)); + @override Widget build(BuildContext context) { switch (reason) { case PageBackReason.back: return Center( - child: BackButton(onPressed: onPressed, color: color), + child: BackButton( + onPressed: onPressed ?? () => _onPressedCallback(context), + color: color), ); case PageBackReason.close: return Center( - child: CloseButton(onPressed: onPressed, color: color), + child: CloseButton( + onPressed: onPressed ?? () => _onPressedCallback(context), + color: color), ); } } diff --git a/lib/view/page_habits_status_changer.dart b/lib/view/page_habits_status_changer.dart index 5ebff6c6..0e3b1e62 100644 --- a/lib/view/page_habits_status_changer.dart +++ b/lib/view/page_habits_status_changer.dart @@ -19,6 +19,7 @@ import 'package:sliver_tools/sliver_tools.dart'; import 'package:tuple/tuple.dart'; import '../common/types.dart'; +import '../common/utils.dart'; import '../component/helper.dart'; import '../component/widget.dart'; import '../extension/context_extensions.dart'; @@ -172,7 +173,8 @@ class _HabitsStatusChangerView extends State { defaultConfirmResult) : true; if (!mounted) return; - if (result) Navigator.of(context).pop(); + + if (result) dismissAllToolTips().then((_) => Navigator.pop(context)); } Widget _buildDebugInfo(BuildContext context) =>