-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Requirements:
-
Offline-First Data Storage:
- Utilize SQLite (via the
sqflitepackage) for local data storage. - Implement data models (e.g.,
Transaction,Category,Party,Transfer,Savings) that include fields forcreatedAt,updatedAt,deletedAt, andlastSyncedAt. - Ensure all data operations (create, update, delete) are performed on the local database first.
- Utilize SQLite (via the
-
Generic Synchronization System:
- Implement a generic synchronization system that can handle multiple data models.
- Use a synchronization queue (
sync_queuetable) to store pending API requests. - The
sync_queuetable should include fields formodelName,operation(create, update, delete),data(JSON representation of the data), andcreatedAt.
-
API Integration:
- Integrate with the provided API (OpenAPI documentation) for data synchronization.
- Implement API services for each data model to perform CRUD operations.
- Handle API responses and update the local database accordingly.
-
Synchronization Logic:
- Implement a synchronization service that periodically processes the synchronization queue.
- Handle potential errors during synchronization (e.g., network issues, API errors).
- Implement logic to pull the latest data from the server, and update the local database.
- Ensure that the sync process is efficient, and does not cause excessive network traffic.
-
Dart/Flutter Implementation:
- Use Dart and Flutter for the implementation.
- Follow clean architecture principles to ensure maintainability and testability.
- Provide clear and concise code with appropriate comments.
Implementation Steps:
-
Set up SQLite Database:
- Initialize the SQLite database using the
sqflitepackage. - Create tables for each data model (e.g.,
transactions,categories,parties). - Create the
sync_queuetable.
- Initialize the SQLite database using the
-
Implement Data Models:
- Create Dart classes for each data model (e.g.,
Transaction,Category). - Include fields for
createdAt,updatedAt,deletedAt, andlastSyncedAt. - Implement
toMap,fromJson, andtoJsonmethods for each model.
- Create Dart classes for each data model (e.g.,
-
Implement Database Helper:
- Create a
DatabaseHelperclass to handle database operations. - Implement generic methods for insert, update, delete, and query.
- Implement methods for enqueueing and processing synchronization queue items.
- Create a
-
Implement API Service:
- Create an
ApiServiceclass to handle API requests. - Implement API methods for each data model (e.g.,
getTransactions,createTransaction). - Handle API responses and convert them to Dart objects.
- Create an
-
Implement Synchronization Service:
- Create a
SyncServiceclass to handle data synchronization. - Implement a method to process the synchronization queue.
- Implement error handling and retry mechanisms.
- Implement logic to pull data from the server, and update the local database.
- Add functions to handle each model (e.g.
_processTransactionSyncItem,_processCategorySyncItem).
- Create a
-
Integrate with Flutter UI:
- Integrate the synchronization service with the Flutter UI.
- Trigger synchronization when network connectivity is restored or at regular intervals.
- Display appropriate loading indicators and error messages.
Code Structure:
lib/
├── models/
│ ├── transaction.dart
│ ├── category.dart
│ ├── party.dart
│ └── ...
├── data/
│ ├── database_helper.dart
│ ├── api_service.dart
│ ├── sync_service.dart
│ ├── sync_handlers/
│ │ ├── model_sync_handler.dart
│ │ ├── transaction_sync_handler.dart
│ │ ├── category_sync_handler.dart (if you add category model)
│ │ ├── party_sync_handler.dart (if you add party model)
│ │ └── ...