-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix guard ScrollController with positions check #4029
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,21 +72,24 @@ class _SpeechProfilePageState extends State<SpeechProfilePage> with TickerProvid | |
|
|
||
| @override | ||
| void dispose() { | ||
| _scrollController.dispose(); | ||
| _questionAnimationController.dispose(); | ||
| super.dispose(); | ||
| } | ||
|
|
||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a race condition here. The |
||
| 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 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
_scrollControlleris not being disposed of in thedisposemethod. 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.