Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Assert or log depending on the context if inherited widget holding selection state is used in a wrong way

ashilkn4f18fff36b11
diff --git a/mobile/lib/ui/viewer/actions/file_selection_overlay_bar.dart b/mobile/lib/ui/viewer/actions/file_selection_overlay_bar.dart
index 1570a5e272..0cfb39c51f 100644
--- a/mobile/lib/ui/viewer/actions/file_selection_overlay_bar.dart
+++ b/mobile/lib/ui/viewer/actions/file_selection_overlay_bar.dart
@@ -117,6 +117,10 @@ class _SelectAllButtonState extends State<SelectAllButton> {
@override
Widget build(BuildContext context) {
final selectionState = SelectionState.of(context);
+ assert(
+ selectionState != null,
+ "SelectionState not found in context, SelectionState should be an ancestor of FileSelectionOverlayBar",
+ );
final colorScheme = getEnteColorScheme(context);
return GestureDetector(
onTap: () {
@@ -155,7 +159,7 @@ class _SelectAllButtonState extends State<SelectAllButton> {
),
const SizedBox(width: 4),
ListenableBuilder(
- listenable: selectionState.selectedFiles,
+ listenable: selectionState!.selectedFiles,
builder: (context, _) {
if (selectionState.selectedFiles.files.length ==
selectionState.allGalleryFiles?.length) {
diff --git a/mobile/lib/ui/viewer/gallery/state/selection_state.dart b/mobile/lib/ui/viewer/gallery/state/selection_state.dart
index a67ffd449f..762b14b94a 100644
--- a/mobile/lib/ui/viewer/gallery/state/selection_state.dart
+++ b/mobile/lib/ui/viewer/gallery/state/selection_state.dart
@@ -1,4 +1,5 @@
import "package:flutter/material.dart";
+import "package:logging/logging.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/selected_files.dart";
@@ -22,10 +23,14 @@ class SelectionState extends InheritedWidget {
return context.dependOnInheritedWidgetOfExactType<SelectionState>();
}
- static SelectionState of(BuildContext context) {
+ static SelectionState? of(BuildContext context) {
final SelectionState? result = maybeOf(context);
- assert(result != null, 'No SelectionState found in context');
- return result!;
+ if (result == null) {
+ Logger("SelectionState").warning(
+ "No SelectionState found in context. Ignore this if file selection is disabled in the gallery used.",
+ );
+ }
+ return result;
}
@override