From 132c270136bfca3295f09c1e244417d9176fefbe Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:32:13 +0530 Subject: [PATCH] [mob] Avoid redudant state refresh when section is not expanded --- .../ui/components/expandable_menu_item_widget.dart | 11 +++++++++-- .../ui/settings/debug/ml_debug_section_widget.dart | 14 ++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/mobile/lib/ui/components/expandable_menu_item_widget.dart b/mobile/lib/ui/components/expandable_menu_item_widget.dart index e212282f68..bedce82e4a 100644 --- a/mobile/lib/ui/components/expandable_menu_item_widget.dart +++ b/mobile/lib/ui/components/expandable_menu_item_widget.dart @@ -10,12 +10,16 @@ class ExpandableMenuItemWidget extends StatefulWidget { final String title; final Widget selectionOptionsWidget; final IconData leadingIcon; + // Expand callback that takes bool as argument + final void Function(bool)? onExpand; + const ExpandableMenuItemWidget({ required this.title, required this.selectionOptionsWidget, required this.leadingIcon, - Key? key, - }) : super(key: key); + this.onExpand, + super.key, + }); @override State createState() => @@ -102,5 +106,8 @@ class _ExpandableMenuItemWidgetState extends State { InheritedSettingsState.maybeOf(context)?.decrement(); } }); + if (widget.onExpand != null) { + widget.onExpand!(expandableController.expanded); + } } } diff --git a/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart b/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart index b51515c5c1..dce805ac00 100644 --- a/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart +++ b/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart @@ -1,5 +1,6 @@ import "dart:async"; +import "package:flutter/foundation.dart"; import 'package:flutter/material.dart'; import "package:logging/logging.dart"; import "package:photos/core/event_bus.dart"; @@ -31,13 +32,17 @@ class MLDebugSectionWidget extends StatefulWidget { class _MLDebugSectionWidgetState extends State { Timer? _timer; + bool isExpanded = false; + final Logger logger = Logger("MLDebugSectionWidget"); @override void initState() { super.initState(); _timer = Timer.periodic(const Duration(seconds: 5), (timer) { - setState(() { - // Your state update logic here - }); + if (isExpanded) { + setState(() { + // Your state update logic here + }); + } }); } @@ -53,11 +58,12 @@ class _MLDebugSectionWidgetState extends State { title: "ML Debug", selectionOptionsWidget: _getSectionOptions(context), leadingIcon: Icons.bug_report_outlined, + onExpand: (p0) => isExpanded = p0, ); } Widget _getSectionOptions(BuildContext context) { - final Logger logger = Logger("MLDebugSectionWidget"); + logger.info("Building ML Debug section options"); return Column( children: [ sectionOptionSpacing,