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

Fixes crashing disposed listeners on a bunch of widgets #164

Merged
merged 1 commit into from
Apr 23, 2021

Conversation

matuella
Copy link
Collaborator

When a QuillController is disposed and then a new instance is added to any QuillToolbar or QuillEditor, a bunch of listeners fail to remove because it has already been disposed of, mostly because of this specific call:

oldWidget.controller.removeListener(_didChangeEditingValue);

I have created a gist for anyone interested in checking out a really easy reproduction.

Full error when tapping the error mentioned
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building Visibility(visible, maintainState, maintainAnimation, maintainSize, maintainSemantics, maintainInteractivity):
A QuillController was used after being disposed.

Once you have called dispose() on a QuillController, it can no longer be used.
The relevant error-causing widget was
QuillToolbar
lib/main_test.dart:39
When the exception was thrown, this was the stack
#0      ChangeNotifier._debugAssertNotDisposed.<anonymous closure>
package:flutter/…/foundation/change_notifier.dart:117
#1      ChangeNotifier._debugAssertNotDisposed
package:flutter/…/foundation/change_notifier.dart:123
#2      ChangeNotifier.removeListener
package:flutter/…/foundation/change_notifier.dart:195
#3      _ToggleStyleButtonState.didUpdateWidget
package:flutter_quill/widgets/toolbar.dart:236
#4      StatefulElement.update
package:flutter/…/widgets/framework.dart:4682
...
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════
A QuillController was used after being disposed.
The relevant error-causing widget was
QuillToolbar
lib/main_test.dart:39
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════
A QuillController was used after being disposed.
The relevant error-causing widget was
QuillToolbar
lib/main_test.dart:39
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════
A QuillController was used after being disposed.
The relevant error-causing widget was
QuillToolbar
lib/main_test.dart:39
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════
A QuillController was used after being disposed.
The relevant error-causing widget was
QuillToolbar
lib/main_test.dart:39
════════════════════════════════════════════════════════════════════════════════

@matuella
Copy link
Collaborator Author

Hey @singerdmx, what do you think about this?

Also, what do you think about adding at least 1 official contributor's PR approval to merge in the main repository? I think this is just to make sure that we have a double check on what is being merged.

@singerdmx singerdmx merged commit 451dffc into singerdmx:master Apr 23, 2021
@singerdmx
Copy link
Owner

Not sure how to set that up ...

@matuella
Copy link
Collaborator Author

matuella commented Apr 23, 2021

https://docs.github.com/en/github/administering-a-repository/managing-a-branch-protection-rule

Here is a quick and easy to follow tutorial!

This is just to make sure that when you are adding new collaborators (like you have done with me), there isn't any way for any of us breaking stuff and adding malicious stuff.

@singerdmx
Copy link
Owner

image
As long as it is easy to revert wrong commit
I have required linear history - hate messy tree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants