-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix null check operator #3950
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
fix null check operator #3950
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 |
|---|---|---|
|
|
@@ -39,14 +39,18 @@ class _ConversationsPageState extends State<ConversationsPage> with AutomaticKee | |
|
|
||
| @override | ||
| void initState() { | ||
| super.initState(); | ||
| WidgetsBinding.instance.addPostFrameCallback((_) async { | ||
| final conversationProvider = Provider.of<ConversationProvider>(context, listen: false); | ||
| if (!mounted) return; | ||
| final conversationProvider = context.read<ConversationProvider>(); | ||
| if (conversationProvider.conversations.isEmpty) { | ||
| await conversationProvider.getInitialConversations(); | ||
| } | ||
|
|
||
| if (!mounted) return; | ||
|
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. This second |
||
|
|
||
| // Load folders for folder tabs | ||
| final folderProvider = Provider.of<FolderProvider>(context, listen: false); | ||
| final folderProvider = context.read<FolderProvider>(); | ||
| if (folderProvider.folders.isEmpty) { | ||
| await folderProvider.loadFolders(); | ||
| } | ||
|
|
@@ -56,7 +60,6 @@ class _ConversationsPageState extends State<ConversationsPage> with AutomaticKee | |
| await _appReviewService.showReviewPromptIfNeeded(context, isProcessingFirstConversation: true); | ||
| } | ||
| }); | ||
| super.initState(); | ||
| } | ||
|
|
||
| void scrollToTop() { | ||
|
|
||
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.
Adding
if (!mounted) return;here is a critical improvement. In asynchronousinitStatecallbacks, especially afterawaitcalls, the widget might be disposed before the callback resumes. Accessingcontextor callingsetStatewhenmountedis false can lead to runtime errors or crashes. This check correctly guards against such scenarios.