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

Fix initialization logic for web #219

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ahmednfwela
Copy link

this moves calling initSummernote from the initState (which doesn't support async initialization) to the build method using a FutureBuilder and an AsyncMemoizer

Comment on lines 566 to 580
child: FutureBuilder<bool>(
future: summernoteInit,
builder: (context, snapshot) {
if (snapshot.hasData) {
return HtmlElementView(
viewType: createdViewId,
);
} else {
return Container(
height: widget
.htmlEditorOptions.autoAdjustHeight
? actualHeight
: widget.otherOptions.height);
}
}))),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you have added a FutureBuilder surrounding the entirety of the build method, do we need this secondary FutureBuilder, as well as the summernoteInit variable? It seems to me we can get rid of this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i haven't noticed this was used to indicate initialization, yes will have to remove it

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, will re-review when you get a chance to remove it :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tneotia should be ok now

Copy link
Owner

@tneotia tneotia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ahmednfwela , sorry for getting back to you so late - I just got around to testing this and found one issue.

Comment on lines +15 to +17
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
setState.call(fn);
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am having issues with this change when the caret selection position is changed on web. The toolbar will not update the values, e.g. font size will not update when the text selection position is changed. Is there any particular reason why you added the postFrameCallback? I don't recall there being any issues with this setState function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's because calling setState during build throws an exception
but now that we moved initialization logic in a future builder i am not sure if this throws or not

but font size not updating is not related to the changes i made, i think

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see any exceptions when this was removed. Also removing this caused the font size to update correctly, the set state was not firing due to the post frame callback. Do you mind testing on your end and making sure there are no side effects to removing this?

@tneotia tneotia mentioned this pull request Apr 12, 2022
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