Skip to content

armgit / ente

Public Imported from GitHub
0

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

Guard deferred UI work after dispose

Neeraj Guptada18dacf3323
diff --git a/mobile/apps/photos/lib/ui/components/buttons/button_widget.dart b/mobile/apps/photos/lib/ui/components/buttons/button_widget.dart
index 8c5192490b..0132df6a95 100644
--- a/mobile/apps/photos/lib/ui/components/buttons/button_widget.dart
+++ b/mobile/apps/photos/lib/ui/components/buttons/button_widget.dart
@@ -213,6 +213,7 @@ class _ButtonChildWidgetState extends State<ButtonChildWidget> {
///to be used as width for the button when the loading/succes states comes.
double? widthOfButton;
final _debouncer = Debouncer(const Duration(milliseconds: 300));
+ Timer? _successResetTimer;
ExecutionState executionState = ExecutionState.idle;
Exception? _exception;
@@ -231,19 +232,24 @@ class _ButtonChildWidgetState extends State<ButtonChildWidget> {
@override
void dispose() {
_debouncer.cancelDebounceTimer();
+ _successResetTimer?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
- if (executionState == ExecutionState.successful) {
- Future.delayed(Duration(seconds: widget.isInAlert ? 1 : 2), () {
- if (mounted) {
+ if (executionState == ExecutionState.successful &&
+ _successResetTimer == null) {
+ _successResetTimer = Timer(
+ Duration(seconds: widget.isInAlert ? 1 : 2),
+ () {
+ _successResetTimer = null;
+ if (!mounted) return;
setState(() {
executionState = ExecutionState.idle;
});
- }
- });
+ },
+ );
}
return GestureDetector(
onTap: _shouldRegisterGestures ? _onTap : null,
diff --git a/mobile/apps/photos/lib/ui/components/buttons/icon_button_widget.dart b/mobile/apps/photos/lib/ui/components/buttons/icon_button_widget.dart
index a03ca6b5bd..557cc790bd 100644
--- a/mobile/apps/photos/lib/ui/components/buttons/icon_button_widget.dart
+++ b/mobile/apps/photos/lib/ui/components/buttons/icon_button_widget.dart
@@ -1,3 +1,5 @@
+import 'dart:async';
+
import 'package:flutter/material.dart';
import 'package:photos/theme/colors.dart';
import 'package:photos/theme/ente_theme.dart';
@@ -35,6 +37,14 @@ class IconButtonWidget extends StatefulWidget {
class _IconButtonWidgetState extends State<IconButtonWidget> {
Color? iconStateColor;
+ Timer? _tapResetTimer;
+
+ @override
+ void dispose() {
+ _tapResetTimer?.cancel();
+ super.dispose();
+ }
+
@override
void didUpdateWidget(IconButtonWidget oldWidget) {
if ((oldWidget.icon != widget.icon ||
@@ -110,16 +120,18 @@ class _IconButtonWidgetState extends State<IconButtonWidget> {
}
void _onTapUp(TapUpDetails details) {
- Future.delayed(const Duration(milliseconds: 100), () {
- if (mounted) {
- setState(() {
- iconStateColor = null;
- });
- }
+ _tapResetTimer?.cancel();
+ _tapResetTimer = Timer(const Duration(milliseconds: 100), () {
+ _tapResetTimer = null;
+ if (!mounted) return;
+ setState(() {
+ iconStateColor = null;
+ });
});
}
void _onTapCancel() {
+ _tapResetTimer?.cancel();
setState(() {
iconStateColor = null;
});
diff --git a/mobile/apps/photos/lib/ui/components/text_input_widget.dart b/mobile/apps/photos/lib/ui/components/text_input_widget.dart
index 2255512d4b..5bffca3169 100644
--- a/mobile/apps/photos/lib/ui/components/text_input_widget.dart
+++ b/mobile/apps/photos/lib/ui/components/text_input_widget.dart
@@ -273,6 +273,7 @@ class _TextInputWidgetState extends State<TextInputWidget> {
void _onSubmit() async {
_debouncer.run(
() => Future(() {
+ if (!mounted) return;
setState(() {
executionState = ExecutionState.inProgress;
});
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
index bcedf5f0ae..587fa012a0 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
@@ -717,6 +717,10 @@ class FileAppBarState extends State<FileAppBar> {
final Collection? sharedLinkCollection = await CollectionActions(
CollectionsService.instance,
).createSharedCollectionLink(context, [file]);
+ if (!mounted) {
+ await dialog.hide();
+ return;
+ }
if (sharedLinkCollection == null) {
await dialog.hide();
return;