[mob][photos] Avoid using .of(context) in initState to stop exceptions from being thrown

This commit is contained in:
ashilkn
2024-06-17 08:41:12 +05:30
parent 4f18fff36b
commit ff1e84d0d8

View File

@@ -108,6 +108,7 @@ class GalleryState extends State<Gallery> {
final _forceReloadEventSubscriptions = <StreamSubscription<Event>>[];
late String _logTag;
bool _sortOrderAsc = false;
List<EnteFile> _allFiles = [];
@override
void initState() {
@@ -214,7 +215,7 @@ class GalleryState extends State<Gallery> {
// group files into multiple groups and returns `true` if it resulted in a
// gallery reload
bool _onFilesLoaded(List<EnteFile> files) {
SelectionState.of(context)?.allGalleryFiles = files;
_allFiles = files;
final updatedGroupedFiles =
widget.enableFileGrouping && widget.groupType.timeGrouping()
@@ -249,6 +250,7 @@ class GalleryState extends State<Gallery> {
@override
Widget build(BuildContext context) {
_logger.finest("Building Gallery ${widget.tagPrefix}");
SelectionState.of(context)?.allGalleryFiles = _allFiles;
if (!_hasLoadedFiles) {
return widget.loadingWidget;
}