From df701d8800217c9d48ecbbfb70e432b5ed9ce26c Mon Sep 17 00:00:00 2001 From: Pinho13 Date: Tue, 12 Nov 2024 11:36:38 +0000 Subject: [PATCH] fix: Double super.initState and Disposed Timer --- .../lib/view/common_widgets/last_update_timestamp.dart | 10 ++++++++-- .../lib/view/restaurant/restaurant_page_view.dart | 1 - 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/uni_app/lib/view/common_widgets/last_update_timestamp.dart b/packages/uni_app/lib/view/common_widgets/last_update_timestamp.dart index 403fb1e19..56e9b8789 100644 --- a/packages/uni_app/lib/view/common_widgets/last_update_timestamp.dart +++ b/packages/uni_app/lib/view/common_widgets/last_update_timestamp.dart @@ -18,11 +18,11 @@ class LastUpdateTimeStamp> class _LastUpdateTimeStampState> extends State { DateTime currentTime = DateTime.now(); - + Timer? timer; @override void initState() { super.initState(); - Timer.periodic( + timer = Timer.periodic( const Duration(seconds: 60), (timer) { if (mounted) { @@ -34,6 +34,12 @@ class _LastUpdateTimeStampState> ); } + @override + void dispose() { + timer?.cancel(); + super.dispose(); + } + @override Widget build(BuildContext context) { return Consumer( diff --git a/packages/uni_app/lib/view/restaurant/restaurant_page_view.dart b/packages/uni_app/lib/view/restaurant/restaurant_page_view.dart index d5933af9b..edd58ac12 100644 --- a/packages/uni_app/lib/view/restaurant/restaurant_page_view.dart +++ b/packages/uni_app/lib/view/restaurant/restaurant_page_view.dart @@ -29,7 +29,6 @@ class _RestaurantPageViewState extends GeneralPageViewState void initState() { super.initState(); final weekDay = DateTime.now().weekday; - super.initState(); tabController = TabController(vsync: this, length: DayOfWeek.values.length); tabController.animateTo(tabController.index + (weekDay - 1)); scrollViewController = ScrollController();