-
Notifications
You must be signed in to change notification settings - Fork 57
Replaced getApplicationDocumentsDirectory() with getApplicationSupportDirectory in io.dart #181
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
base: main
Are you sure you want to change the base?
Conversation
…tDirectory in io.dart
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.
Pull Request Overview
This PR updates the directory selection strategy in the store implementation by replacing the use of getApplicationDocumentsDirectory()
with getApplicationSupportDirectory()
for better alignment with platform conventions.
- Switched from documents directory to application support directory for data storage
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Future<Directory> _getDocumentDir() async { | ||
try { | ||
return await getApplicationDocumentsDirectory(); | ||
return await getApplicationSupportDirectory(); |
Copilot
AI
Sep 16, 2025
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.
This change modifies where application data is stored, which could be a breaking change for existing users. Consider implementing a migration strategy to move existing data from the documents directory to the application support directory, or provide a configuration option to maintain backward compatibility.
return await getApplicationSupportDirectory(); | |
final newDir = await getApplicationSupportDirectory(); | |
final oldDir = await getApplicationDocumentsDirectory(); | |
// Migrate old files if they exist | |
final oldFiles = oldDir | |
.listSync() | |
.whereType<File>() | |
.where((file) => file.path.contains('analytics-flutter-') && file.path.endsWith('.json')); | |
for (final oldFile in oldFiles) { | |
final fileName = oldFile.uri.pathSegments.last; | |
final newFile = File('${newDir.path}/$fileName'); | |
if (!await newFile.exists()) { | |
await oldFile.copy(newFile.path); | |
await oldFile.delete(); | |
} | |
} | |
return newDir; |
Copilot uses AI. Check for mistakes.
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.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
} catch (e) { | ||
// The app should continue to work even if migration fails | ||
} | ||
} | ||
} | ||
} catch (e) { | ||
// Migration failure shouldn't break the app |
Copilot
AI
Sep 23, 2025
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 catch block silently ignores all exceptions during file operations. Consider logging the error for debugging purposes while still allowing the app to continue.
} catch (e) { | |
// The app should continue to work even if migration fails | |
} | |
} | |
} | |
} catch (e) { | |
// Migration failure shouldn't break the app | |
} catch (e, stackTrace) { | |
// The app should continue to work even if migration fails | |
print('File migration error: \$e'); | |
print(stackTrace); | |
} | |
} | |
} | |
} catch (e, stackTrace) { | |
// Migration failure shouldn't break the app | |
print('Migration failure: \$e'); | |
print(stackTrace); |
Copilot uses AI. Check for mistakes.
// The app should continue to work even if migration fails | ||
} | ||
} | ||
} | ||
} catch (e) { | ||
// Migration failure shouldn't break the app |
Copilot
AI
Sep 23, 2025
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 catch block silently ignores all exceptions during migration. Consider logging the error for debugging purposes while still allowing the app to continue.
// The app should continue to work even if migration fails | |
} | |
} | |
} | |
} catch (e) { | |
// Migration failure shouldn't break the app | |
// The app should continue to work even if migration fails | |
print('Error migrating file ${oldFile.path} to $newFilePath: $e'); | |
} | |
} | |
} | |
} catch (e) { | |
// Migration failure shouldn't break the app | |
print('Error during migration from Documents to Support directory: $e'); |
Copilot uses AI. Check for mistakes.
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.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This PR does following:
Replaces getApplicationDocumentsDirectory() with getApplicationSupportDirectory so that SDK files are not publically visible.
Moves the JSON files from Old directory to New directory.
When storageJson is turned on, the queued events are no longer deleted from the analytics-flutter-queue_flushing_plugin.json file if they cannot be sent due to any reason (ex. Network Error). They are attempted again according to the Flush policy.