Skip to content

Commit

Permalink
Fix #630 kおんどこsお
Browse files Browse the repository at this point in the history
  • Loading branch information
shiosyakeyakini-info committed Nov 10, 2024
1 parent f4660f4 commit e0b8661
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions lib/view/note_create_page/vote_area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class VoteContentListItem extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final onVoteContentChange = ref.watch(
noteCreateNotifierProvider
.select((notifier) => notifier.voteContent.length),
.select((notifier) => notifier.voteContentCount),
);

final initial = useMemoized(
Expand All @@ -78,26 +78,22 @@ class VoteContentListItem extends HookConsumerWidget {
final controller = useTextEditingController(text: initial);
useEffect(
() {
controller.text = initial;
return null;
},
[initial],
);
useEffect(
() {
controller.addListener(() {
if (ref.read(noteCreateNotifierProvider).voteContent.length <=
index) {
return;
}
final notifier = ref.read(noteCreateNotifierProvider.notifier);
WidgetsBinding.instance.addPostFrameCallback((_) {
notifier.setVoteContent(index, controller.text);
controller
..text = initial
..addListener(() {
final voteContent =
ref.read(noteCreateNotifierProvider).voteContent;
if (voteContent.length <= index ||
voteContent[index] == controller.text) {
return;
}
ref
.read(noteCreateNotifierProvider.notifier)
.setVoteContent(index, controller.text);
});
});
return null;
},
[index, initial],
[index, onVoteContentChange],
);
return Padding(
padding: const EdgeInsets.only(bottom: 5),
Expand Down

0 comments on commit e0b8661

Please sign in to comment.