Skip to content

Commit

Permalink
fix: avoid updating PostNotifier state if text is not changed (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon authored Oct 29, 2024
1 parent 04f1cd7 commit 1dfc491
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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.

0 comments on commit 1dfc491

Please sign in to comment.