Skip to content

Commit

Permalink
move initialization to initState()
Browse files Browse the repository at this point in the history
  • Loading branch information
HaonRekcef committed Sep 7, 2024
1 parent 03c5f21 commit 9e59e48
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lib/src/view/analysis/analysis_share_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ class _EditPgnTagsFormState extends ConsumerState<_EditPgnTagsForm> {
final Map<String, TextEditingController> _controllers = {};
final Map<String, FocusNode> _focusNodes = {};

@override
void initState() {
super.initState();
final ctrlProvider = analysisControllerProvider(widget.pgn, widget.options);
final pgnHeaders = ref.read(ctrlProvider).pgnHeaders;

for (final entry in pgnHeaders.entries) {
_controllers[entry.key] = TextEditingController(text: entry.value);
_focusNodes[entry.key] = FocusNode();
_focusNodes[entry.key]!.addListener(() {
if (!_focusNodes[entry.key]!.hasFocus) {
ref.read(ctrlProvider.notifier).updatePgnHeader(
entry.key,
_controllers[entry.key]!.text,
);
}
});
}
}

@override
void dispose() {
for (final controller in _controllers.values) {
Expand Down Expand Up @@ -123,20 +143,6 @@ class _EditPgnTagsFormState extends ConsumerState<_EditPgnTagsForm> {
(e) => showRatings || !_ratingHeaders.contains(e.key),
)
.mapIndexed((index, e) {
if (!_controllers.containsKey(e.key)) {
_controllers[e.key] =
TextEditingController(text: e.value);
_focusNodes[e.key] = FocusNode();
_focusNodes[e.key]!.addListener(() {
if (!_focusNodes[e.key]!.hasFocus) {
ref.read(ctrlProvider.notifier).updatePgnHeader(
e.key,
_controllers[e.key]!.text,
);
}
});
}

return Padding(
padding: Styles.horizontalBodyPadding
.add(const EdgeInsets.only(bottom: 8.0)),
Expand Down

0 comments on commit 9e59e48

Please sign in to comment.