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: avoid updating PostNotifier state if text is not changed #459

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/provider/post_notifier_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,13 @@ class PostNotifier extends _$PostNotifier {
}

void setCw(String? cw) {
state = state.copyWith(cw: cw?.isNotEmpty ?? false ? cw : null);
if ((cw == null || cw.isEmpty) && state.cw != null) {
state = state.copyWith(cw: null);
} else if (cw != state.cw) {
state = state.copyWith(cw: cw);
} else {
return;
}
_scheduleSave();
}

Expand Down Expand Up @@ -462,7 +468,13 @@ class PostNotifier extends _$PostNotifier {
}

void setText(String? text) {
state = state.copyWith(text: text?.isNotEmpty ?? false ? text : null);
if ((text == null || text.isEmpty) && state.text != null) {
state = state.copyWith(text: null);
} else if (text != state.text) {
state = state.copyWith(text: text);
} else {
return;
}
_scheduleSave();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/provider/post_notifier_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading