Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Fix exceptions from calling dependOnInheritedWidgetOfExactType in init state

ashilknd976986473d6
diff --git a/mobile/lib/ui/home/loading_photos_widget.dart b/mobile/lib/ui/home/loading_photos_widget.dart
index 2980fd34bb..f5c9dd8443 100644
--- a/mobile/lib/ui/home/loading_photos_widget.dart
+++ b/mobile/lib/ui/home/loading_photos_widget.dart
@@ -25,7 +25,7 @@ class LoadingPhotosWidget extends StatefulWidget {
class _LoadingPhotosWidgetState extends State<LoadingPhotosWidget> {
late StreamSubscription<SyncStatusUpdate> _firstImportEvent;
- late StreamSubscription<LocalImportProgressEvent> _importProgressEvent;
+ StreamSubscription<LocalImportProgressEvent>? _importProgressEvent;
int _currentPage = 0;
late String _loadingMessage;
final PageController _pageController = PageController(
@@ -38,7 +38,6 @@ class _LoadingPhotosWidgetState extends State<LoadingPhotosWidget> {
@override
void initState() {
super.initState();
- _loadingMessage = S.of(context).loadingYourPhotos;
Future.delayed(const Duration(seconds: 60), () {
oneMinuteOnScreen.value = true;
});
@@ -53,19 +52,14 @@ class _LoadingPhotosWidgetState extends State<LoadingPhotosWidget> {
context,
BackupFolderSelectionPage(
isOnboarding: true,
+ //Move this from here?
buttonText: S.of(context).startBackup,
),
);
}
}
});
- _importProgressEvent =
- Bus.instance.on<LocalImportProgressEvent>().listen((event) {
- _loadingMessage = S.of(context).processingImport(event.folderName);
- if (mounted) {
- setState(() {});
- }
- });
+
_didYouKnowTimer =
Timer.periodic(const Duration(seconds: 5), (Timer timer) {
if (!mounted) {
@@ -85,10 +79,26 @@ class _LoadingPhotosWidgetState extends State<LoadingPhotosWidget> {
});
}
+ @override
+ void didChangeDependencies() {
+ super.didChangeDependencies();
+ if (_importProgressEvent != null) {
+ _importProgressEvent!.cancel();
+ } else {
+ _importProgressEvent =
+ Bus.instance.on<LocalImportProgressEvent>().listen((event) {
+ _loadingMessage = S.of(context).processingImport(event.folderName);
+ if (mounted) {
+ setState(() {});
+ }
+ });
+ }
+ }
+
@override
void dispose() {
_firstImportEvent.cancel();
- _importProgressEvent.cancel();
+ _importProgressEvent?.cancel();
_didYouKnowTimer.cancel();
oneMinuteOnScreen.dispose();
super.dispose();
@@ -96,6 +106,9 @@ class _LoadingPhotosWidgetState extends State<LoadingPhotosWidget> {
@override
Widget build(BuildContext context) {
+ if (_importProgressEvent == null) {
+ _loadingMessage = S.of(context).loadingYourPhotos;
+ }
_setupLoadingMessages(context);
final isLightMode = Theme.of(context).brightness == Brightness.light;
return Scaffold(