[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:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user