Feature - #551 - Auto Clear History
Foss Hack 2025 - Auto Clear History via WidgetBindingObserver & State Mgmt for Dynamic Clean Up
Team Dart Knight
- User -
Vishwa Karthik - Mail -
[email protected]
Relevant PR for Clearing API History
Debug Considerations
- Enrolled new enum value of 5second for HistoryRentetionPeriod for debugging purposes.
- The final PR will have clean code
Checklist
- [✅ ] I have gone through the contributing guide
- [✅] I have updated my branch and synced it with project
mainbranch before making this PR - [✅ ] I am using the latest Flutter stable branch (run
flutter upgradeand verify) - [✅ ] I have run the tests (
flutter test) and all tests are passing
Added/updated tests?
We encourage you to add relevant test cases.
- [ ] Yes
- [✅ ] No, and this is why: please replace this line with details on why tests have not been included
OS on which you have developed and tested the feature?
- [✅] Android
- [✅ ] Windows
- [ ] macOS
- [ ] Linux
cc: @ashitaprasad
History Service Implementation for Auto-Clearing API Requests
Team Dart Knight
- User -
Vishwa Karthik - Mail -
[email protected]
Do Checkout
Overview
This document outlines the implementation of the autoClearHistory feature in APIDASH to efficiently manage stored API request history while maintaining a smooth user experience across all supported platforms.
Features
Auto-Clear History on App Launch
-
When the app is launched, it automatically clears 50 old API records to prevent excessive local storage usage.
-
This helps in keeping the app responsive and prevents unnecessary memory consumption.
-
Triggered using autoClearHistory() from HistoryServiceImpl.
Dynamic Auto-Clear Trigger (State Management-Based)
-
Uses Riverpod StateNotifier to monitor the API request list dynamically.
-
If the length exceeds 50, the history clearance is automatically triggered, just to avoid heavy duty on app launch.
-
Reason to use State management here is to resist unnecessary local database call because user may keep switching apps/window during development cycle.
Platform-Specific Cleanup Handling
-
For Android & iOS: Uses AppLifecycleState.paused via WidgetsBindingObserver to trigger autoClearHistory() when the app goes to the background.
-
For Windows, macOS, Linux:Uses window_manager to detect app minimize events and trigger cleanup accordingly.
-
Ensures proper handling since AppLifecycleState does not work on desktops.
Batch Deletion Strategy
-
Deleting 50 records at a time minimizes performance issues.
-
Ensures smooth UX by avoiding excessive database transactions.
-
Users can continue adding new requests seamlessly without experiencing lag.
cc: @ashitaprasad
Moved project doc to https://github.com/foss42/apidash/blob/main/doc/proposals/2025/fosshack/dark_knight_history.md
To be reviewed by @DenserMeerkat
@ashitaprasad
Platforms tested
- [X] Windows
- [X] Android
Observation
The auto-clearing works in the platforms tested. But the history providers are not updated after clearing files hence the deleted history cards are still shown in the UI.
Other Comments
The app.dart now has 2 ConsumerStatefulWidget with WindowListener mixins which feels redundant and can be tidied up