From 70303761379389400325ac4de92f83bf56254ece Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Sat, 3 Jul 2021 19:32:23 +0800 Subject: [PATCH] Fix accessing context during initState --- lib/widget/album_picker_dialog.dart | 6 +++++- lib/widget/archive_viewer.dart | 6 +++++- lib/widget/home_albums.dart | 6 +++++- lib/widget/home_photos.dart | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/widget/album_picker_dialog.dart b/lib/widget/album_picker_dialog.dart index 596f694f..350b7a0f 100644 --- a/lib/widget/album_picker_dialog.dart +++ b/lib/widget/album_picker_dialog.dart @@ -66,7 +66,11 @@ class _AlbumPickerDialogState extends State { _reqQuery(); } else { // process the current state - _onStateChange(context, _bloc.state); + WidgetsBinding.instance.addPostFrameCallback((_) { + setState(() { + _onStateChange(context, _bloc.state); + }); + }); } } diff --git a/lib/widget/archive_viewer.dart b/lib/widget/archive_viewer.dart index fb5f6e30..fc25745e 100644 --- a/lib/widget/archive_viewer.dart +++ b/lib/widget/archive_viewer.dart @@ -83,7 +83,11 @@ class _ArchiveViewerState extends State _reqQuery(); } else { // process the current state - _onStateChange(context, _bloc.state); + WidgetsBinding.instance.addPostFrameCallback((_) { + setState(() { + _onStateChange(context, _bloc.state); + }); + }); } } diff --git a/lib/widget/home_albums.dart b/lib/widget/home_albums.dart index ca6e9f21..f4401297 100644 --- a/lib/widget/home_albums.dart +++ b/lib/widget/home_albums.dart @@ -82,7 +82,11 @@ class _HomeAlbumsState extends State { _reqQuery(); } else { // process the current state - _onStateChange(context, _bloc.state); + WidgetsBinding.instance.addPostFrameCallback((_) { + setState(() { + _onStateChange(context, _bloc.state); + }); + }); } } diff --git a/lib/widget/home_photos.dart b/lib/widget/home_photos.dart index 8dc80167..afb8cfde 100644 --- a/lib/widget/home_photos.dart +++ b/lib/widget/home_photos.dart @@ -83,7 +83,11 @@ class _HomePhotosState extends State _reqQuery(); } else { // process the current state - _onStateChange(context, _bloc.state); + WidgetsBinding.instance.addPostFrameCallback((_) { + setState(() { + _onStateChange(context, _bloc.state); + }); + }); } }