Skip to content
Merged
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
19 changes: 11 additions & 8 deletions app/lib/pages/speech_profile/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,24 @@ class _SpeechProfilePageState extends State<SpeechProfilePage> with TickerProvid

@override
void dispose() {
_scrollController.dispose();
_questionAnimationController.dispose();
super.dispose();
}
Comment on lines 74 to 77
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The _scrollController is not being disposed of in the dispose method. This can lead to memory leaks. It should be disposed of by calling _scrollController.dispose() to release its resources when the State object is removed from the tree permanently.


final ScrollController _scrollController = ScrollController();

void scrollDown() async {
if (_scrollController.hasClients) {
await Future.delayed(const Duration(milliseconds: 250));
_scrollController.animateTo(
_scrollController.position.maxScrollExtent,
duration: const Duration(milliseconds: 200),
curve: Curves.easeOut,
);
}
Comment on lines 82 to -89
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

There is a race condition here. The _scrollController.hasClients check is performed before an await. After the Future.delayed completes, the widget might have been disposed, and _scrollController might no longer have clients. Accessing _scrollController.position would then throw an exception. The checks for mounted and hasClients (or positions.isNotEmpty) should be performed after any await calls to ensure the state is still valid before using the controller.

await Future.delayed(const Duration(milliseconds: 250));

if (!mounted) return;
if (_scrollController.positions.isEmpty) return;

_scrollController.animateTo(
_scrollController.position.maxScrollExtent,
duration: const Duration(milliseconds: 200),
curve: Curves.easeOut,
);
}

@override
Expand Down