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

This commit is contained in:
Neeraj Gupta
2025-01-08 16:32:13 +05:30
parent 188bb4a9f4
commit 132c270136
2 changed files with 19 additions and 6 deletions

View File

@@ -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);
}
}
}

View File

@@ -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,