Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob] Avoid redudant state refresh when section is not expanded

Neeraj Gupta132c270136bf
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<ExpandableMenuItemWidget> createState() =>
@@ -102,5 +106,8 @@ class _ExpandableMenuItemWidgetState extends State<ExpandableMenuItemWidget> {
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<MLDebugSectionWidget> {
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<MLDebugSectionWidget> {
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,