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

A TabController was used after being disposed. #216

Closed
AAverin opened this issue Feb 11, 2021 · 3 comments
Closed

A TabController was used after being disposed. #216

AAverin opened this issue Feb 11, 2021 · 3 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@AAverin
Copy link

AAverin commented Feb 11, 2021

I am trying to rebuild my tabController depending on some feature flags being on or off.

final featureFlags = useState(database.getFeatureFlags());
database.featureFlagsBox.watch(key: "feature_flags").listen((event) {
      featureFlags.value = event.value;
    });
final allPages = useMemoized(() {
      return _buildPages(featureFlags.value);
    }, [featureFlags.value]);
final _ticker = useSingleTickerProvider();
final _tabController = useTabController(initialLength: allPages.length, vsync: _ticker, keys: [featureFlags.value]);

Doing that results in and error:

The following assertion was thrown building CollectionsPage(dirty, dependencies: [_EffectiveTickerMode, _LocalizationsScope-[GlobalKey#13ef1], _InheritedTheme], useState<FeatureFlags>: Instance of 'FeatureFlags', useMemoized<List<PageViewDescription>>: [Instance of 'PageViewDescription'], useSingleTickerProvider):
A TabController was used after being disposed.

Once you have called dispose() on a TabController, it can no longer be used.
The relevant error-causing widget was: 
  CollectionsPage .../lib/components/screens/home/HomeScreen.dart:44:67
When the exception was thrown, this was the stack: 
#0      ChangeNotifier._debugAssertNotDisposed.<anonymous closure> (package:flutter/src/foundation/change_notifier.dart:117:9)
#1      ChangeNotifier._debugAssertNotDisposed (package:flutter/src/foundation/change_notifier.dart:123:6)
#2      ChangeNotifier.dispose (package:flutter/src/foundation/change_notifier.dart:212:12)
#3      TabController.dispose (package:flutter/src/material/tab_controller.dart:299:11)
#4      _TabControllerHookState.dispose (package:flutter_hooks/src/tab_controller.dart:57:33)

Probably related to #81

@AAverin AAverin added bug Something isn't working needs triage labels Feb 11, 2021
@rrousselGit
Copy link
Owner

Sorry for the late reply. Could you share a complete snippet and steps to reproduce the problem?

The code you gave isn't enough to reproduce it.

@rrousselGit rrousselGit added question Further information is requested and removed needs triage labels Nov 28, 2021
@AAverin
Copy link
Author

AAverin commented Nov 28, 2021

Wow, ok, this was a long time ago =) I have either found a fix or a workaround, or removed flags.
I will try to dig into my code to find some details.

@rrousselGit
Copy link
Owner

Haha thanks!

@rrousselGit rrousselGit self-assigned this May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants