Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[problem with VisibilityDetector?] Bad state: No ProviderScope found. Error thrown during a task callback. #2907

Closed
peterweb2005 opened this issue Sep 15, 2023 · 5 comments
Assignees
Labels
bug Something isn't working needs triage

Comments

@peterweb2005
Copy link

only found in crash report, which i cant reproduce

error log

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Bad state: No ProviderScope found. Error thrown during a task callback.
at ProviderScope.containerOf(framework.dart:107)
at ConsumerStatefulElement.read(consumer.dart:613)
at _ListHeaderWidget.build.(xx_page.dart:278)
at VisibilityDetectorLayer._fireCallback(visibility_detector_layer.dart:263)
at VisibilityDetectorLayer._processCallbacks(visibility_detector_layer.dart:222)
at _TaskEntry.run(binding.dart:92)
at SchedulerBinding.handleEventLoopCallback(binding.dart:515)
at SchedulerBinding._runTasks(binding.dart:490)
at TickerFuture.whenCompleteOrCancel.thunk(ticker.dart:420)

purpose of this code is to detect if the progress view container is visible, which this view is in a "list header"
else show center progress view

              // consume progress
              SizedBox(
                width: 24,
                height: 24,
                child: VisibilityDetector(
                  key: _progressViewVisiblityKey,
                  onVisibilityChanged: (VisibilityInfo visibilityInfo) {
                    log.finest('visibilityInfo: ', visibilityInfo);
                    final visible = visibilityInfo.visibleBounds != Rect.zero;
                    log.finest('visible: ', visible);
                    ref.read(progressViewVisibleProvider.notifier).state =
                        visible;
                  },
                  child: Consumer(builder: (context, ref, child) {
                    final progress =
                        ref.watch(requestProvider.select((e) => e.progress));
                    log.finest('progress: ', progress);
                    if (progress) {
                      final visible = ref.watch(progressViewVisibleProvider);
                      log.finest('visible: ', visible);
                      if (visible) {
                        return CircularProgressIndicator(
                            valueColor: AlwaysStoppedAnimation(
                                StyleUtil.getColorScheme().fg1));
                      }
                    }
                    return Container();
                  }),
                ),
              ),
@peterweb2005
Copy link
Author

peterweb2005 commented Sep 15, 2023

(as revision) it is a view in slivers of CustomScrollView, is it disposed? so no scope?

EDITED
as #1346?

EDITED
published to see

EDITED

Revision

i found that it is not a item in list view, it is a view in slivers of CustomScrollView

CustomScrollView(
          controller: scrollController,
          // cacheExtent: 3000,
          slivers: [
            // list head
            SliverToBoxAdapter(child: _buildListItem(item, 0)),
            // list view ...

@rrousselGit
Copy link
Owner

if your widget got disposed, ref.read will throw, yes.

@rrousselGit
Copy link
Owner

It's similar to how using BuildContext throws on unmounted widgets

@peterweb2005
Copy link
Author

peterweb2005 commented Sep 16, 2023

no crash log,
but sorry, i think still need to notify the change event (as it really happened), otherwise lost

EDIT
trying useEffect() hook to listen dispose event

@peterweb2005
Copy link
Author

Sorry, forgot to tell how I resolved

  1. keep notifier on init
  2. on dispose, use that notifier, so no need the ref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants