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

This commit is contained in:
ashilkn
2024-06-17 08:16:31 +05:30
parent 1e8f739ef2
commit 4f18fff36b
2 changed files with 13 additions and 4 deletions

View File

@@ -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) {

View File

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