Skip to content
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

Architecture improvements #24

Open
wants to merge 193 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
193 commits
Select commit Hold shift + click to select a range
63fb593
feat: add support to save translation details in phone database
rajey Dec 5, 2022
fa386b7
Merge branch 'develop' of github.com:dhis2-club-tanzania/dhis2-flutte…
rajey Dec 5, 2022
36ab0db
refactor: abstract database location methods in own class
rajey Dec 5, 2022
a34b894
refactor: improve dependency injection on query and repository classes
rajey Dec 7, 2022
8f7c8d2
fix: resolve database references in models
rajey Dec 7, 2022
f3cad3b
feat: add http module under d2 instance & resolve dependency issues
rajey Dec 7, 2022
6a82e16
fix: resolve data element module dependencies
rajey Dec 7, 2022
cb76916
fix: resolve translation issues on data element model
rajey Dec 7, 2022
295d2e0
refactor: organise program stage tests
rajey Dec 7, 2022
434c71f
refactor: organise program rule tests
rajey Dec 7, 2022
760431e
refactor: organisse program rule codes and dependencies
rajey Dec 7, 2022
af8956f
test: fix affected tests for orgunit metadata
rajey Dec 8, 2022
b55dcb0
fix: resolve test issues in saving tracked entity attributes
rajey Dec 8, 2022
dc6740e
test: organise reversed attribute tests
rajey Dec 8, 2022
e318b62
test: organise file resource tests
rajey Dec 8, 2022
772072d
fix: resolve contraints issues on program stage and event models
rajey Dec 10, 2022
13d73aa
fix: resolve orgunit constraint issues on saving event
rajey Dec 10, 2022
b8c9048
refactor: organise test files for aggregate module
rajey Dec 10, 2022
b55f6b3
fix: resolve test issues with validation rule execution
rajey Dec 10, 2022
15c493b
test: organise tests for notification module
rajey Dec 10, 2022
1c5a00a
test: organise test for dashboard module
rajey Dec 10, 2022
88a465b
fix: resolve unique contraints issue imposed by queuing
rajey Dec 10, 2022
7b4af65
fix: resolve failed tests following file updates
rajey Dec 10, 2022
663dd8c
fix: resolve user module reference issues
rajey Dec 10, 2022
12e71eb
fix: resolve linting issues
rajey Dec 10, 2022
52eefc3
Merge branch 'develop' of github.com:dhis2-club-tanzania/dhis2-flutte…
rajey Dec 10, 2022
6f49579
Merge branch 'feature/translation-support' into develop
rajey Dec 10, 2022
2da84de
fix: resolve unused import issues
rajey Dec 10, 2022
213281f
safe commit
mdachi-codes Feb 13, 2023
a195fcd
Merge branch 'develop' of github.com:udsm-dhis2-lab/d2-touch into dev…
mdachi-codes Feb 28, 2023
3f2e1b1
log url and responses
mdachi-codes Mar 5, 2023
203a579
donwload and save display on list property if tei attributes
mdachi-codes Mar 8, 2023
b0263a5
Clean packages before database build
BaharaJr Mar 19, 2023
e7f1264
feat: Add Program Relationship entity
yuzalsif Mar 19, 2023
6e8ce3a
feat: Add program relationship entity to queries
yuzalsif Mar 19, 2023
c8502fc
feat: Add program relationship query to program module
yuzalsif Mar 19, 2023
8924ae8
remove rootJunction on dhis url
mdachi-codes Mar 19, 2023
7bffa3a
Merge branch 'develop' of github.com:udsm-dhis2-lab/d2-touch into dev…
mdachi-codes Mar 19, 2023
c7e3238
chore: clear logs
mdachi-codes Mar 19, 2023
653d586
fix: Update the urls in mock tests
yuzalsif Mar 19, 2023
bd8c779
fix: add code property to program tracked entity attribute
mdachi-codes Mar 19, 2023
34908b8
feat: Add download program relationships metadata
yuzalsif Mar 19, 2023
8cb9cb4
Merge pull request #15 from udsm-dhis2-lab/feature/program-relationships
rajey Mar 19, 2023
3cc8ed6
Remove duplicate code definition
BaharaJr Mar 19, 2023
73995e6
Add initialize for display in list
BaharaJr Mar 19, 2023
0264875
fix: return code on program tracked entity attribute
mdachi-codes Mar 19, 2023
e0a798b
feat: Add tracked entity instance relationship
yuzalsif Mar 19, 2023
e4710d3
feat: Add get user by user groups
yuzalsif Mar 20, 2023
f47f293
Fix error in assigning empty dataElements
BaharaJr Mar 20, 2023
270393a
Merge pull request #18 from udsm-dhis2-lab/feature/get-users-by-user-…
rajey Mar 21, 2023
bf74053
Merge pull request #17 from udsm-dhis2-lab/feature/program-relationships
rajey Mar 21, 2023
f9dc55f
feat: Add gender and jobTitle fields in the User entity
yuzalsif Mar 21, 2023
7c0105b
Merge pull request #19 from udsm-dhis2-lab/fix/get-users-by-user-groups
BaharaJr Mar 21, 2023
75179ea
Fix error in failing rules execution due to missing dataElements
BaharaJr Mar 22, 2023
0243540
fix: Add code attribute in userGroup
yuzalsif Mar 22, 2023
125f096
feat: Add data store support
yuzalsif Mar 23, 2023
9c7db85
Merge pull request #21 from udsm-dhis2-lab/feat/data-store
BaharaJr Mar 23, 2023
cd7d695
Merge branch 'develop' into fix/get-users-by-user-groups
BaharaJr Mar 23, 2023
f056709
Merge pull request #20 from udsm-dhis2-lab/fix/get-users-by-user-groups
BaharaJr Mar 23, 2023
cd36d03
Raw queries to engine module
BaharaJr Mar 23, 2023
9e571b6
Fix error with missing code in usergroup entity
BaharaJr Mar 24, 2023
7c2467d
fix: resolve relation attribute naming that prevent relationship to b…
rajey Mar 28, 2023
3ff9670
feat: add support to download related trackedentity instances
rajey Mar 29, 2023
f330394
Merge pull request #22 from udsm-dhis2-lab/feature/relationship-data-…
rajey Mar 29, 2023
3a48b92
feat: Add fetch users by org unit
yuzalsif Apr 12, 2023
dc3ea55
Merge pull request #23 from udsm-dhis2-lab/feat/down-users-by-orgu
yuzalsif Apr 12, 2023
d1e5c3d
feat: chore: Update dependencies
yuzalsif Apr 27, 2023
ffe4704
feat: Add implementation of the four methods
yuzalsif May 4, 2023
1dd89f3
feat: Expose the post
yuzalsif May 18, 2023
c4d0f4c
Add sort order to program section attribute
BaharaJr Mar 30, 2023
d745a8e
Merge
BaharaJr Jun 22, 2023
c7d5b0c
Add code to program stages
BaharaJr Jun 23, 2023
c8fab7a
Improved error handling on syncing
MorleyMinde Jun 23, 2023
619571c
fix: resolve failing test for program module
Jul 3, 2023
6a023fa
test: update http links in test files
Jul 4, 2023
c5ef94f
test: resolve user modules test issues
Jul 4, 2023
1314432
fix: resolve issues in downloading orgunit and programs
Jul 17, 2023
b47ef8d
fix: resolve issues in updating data value set sync status
Jul 18, 2023
dacc9b8
feat: add model for data value set import summary
Jul 19, 2023
868662e
refactor: update data value import summary json to match actual one r…
Jul 19, 2023
cebdbe3
feat: add support to download and save dataset setions
Jul 22, 2023
46559e3
feat: add support to return section as part of dataset query
Jul 22, 2023
639ddaf
feat: add support to return dataset section data elements
Jul 22, 2023
00c2041
fix: resolve dataset url typo
Jul 22, 2023
3470ab8
refactor: make data element label for api consitent with database column
Jul 23, 2023
4e11cf3
feat: add support to download and store categoy option combo
Jul 24, 2023
d0884c2
feat: add support to return category combo in data set element query
Jul 24, 2023
978a42e
fix: resolve issues in handling null code in category option combo
Jul 25, 2023
2e39b65
feat: add support to skip date update on tracked entity instance
Jul 25, 2023
56a932e
test: update organisation unit failed tests
Jul 25, 2023
31cb864
fix: remove unused imports
Jul 25, 2023
5f99408
fix: resolve auth failed tests
Jul 25, 2023
6baedb7
fix: resolve reference issues on non column attributes
BaharaJr Jul 26, 2023
651c0c8
feat: add support to clear shared preference on logout
Aug 6, 2023
3981b2c
Merge branch 'develop' of github.com:udsm-dhis2-lab/d2-touch into dev…
Aug 6, 2023
4c735a6
chore: bump library version to 1.1.0
Aug 6, 2023
1d2678e
chore: update sdk version ranges
Aug 6, 2023
374c249
feat: add support to include relationship in tracker payload
Aug 7, 2023
d2c762f
chore: bump sdk version to 1.1.1
Aug 7, 2023
aa33a5b
feat: add support to include other orgunit parent children
Aug 9, 2023
7bd4088
fix: resolve issues in downloading orgunit when include parent childr…
Aug 9, 2023
bac46ef
feat: add support to filter by subject in message conversation
Aug 10, 2023
03fc6b6
fix: Fix data sync in weekly-report
yuzalsif Aug 21, 2023
72c9d08
feat: add support to download greyed section fields
rajey Sep 8, 2023
72c0e4f
Add program to event payload and remove double quoted values
BaharaJr Sep 27, 2023
aee55d9
refactor tracked entity atribute
wile44 Sep 27, 2023
6f5b595
Add optional resource name to upload events
BaharaJr Sep 27, 2023
e7813df
remove unused codes
wile44 Sep 29, 2023
facd155
Remove hardcoded mcr code
BaharaJr Sep 29, 2023
8d7237b
Add occurred at date to event
BaharaJr Sep 29, 2023
d23e77b
add enrollment value on event upload
wile44 Oct 2, 2023
363d048
Check for parent nullability in orgunits
BaharaJr Oct 10, 2023
7bd742c
improve tracked entities instance
wile44 Nov 6, 2023
79539e2
fix: null handling statement
wile44 Nov 7, 2023
badc266
refactor code tracked attribute instance
wile44 Nov 7, 2023
56a6519
fix: event synchronization related to acd forms
wile44 Nov 8, 2023
4a98a6e
improve functions and parameter in event rule engine
wile44 Nov 10, 2023
5dd07c9
add: d2 functions implementation
wile44 Nov 10, 2023
598ef36
implementation of d2 function
wile44 Nov 28, 2023
06437b0
Remove unused lines of code
BaharaJr Dec 15, 2023
49f539a
fix typo for better ux
wile44 Dec 19, 2023
84e56a9
Merge branch 'develop' of https://github.com/udsm-dhis2-lab/d2-touch …
wile44 Dec 19, 2023
b9fa965
d2 function implementation
wile44 Jan 15, 2024
e69e71f
refactor d2 function
wile44 Jan 15, 2024
4fae231
remove unused code in d2 functions
wile44 Jan 16, 2024
aad90d3
add lastupdated date in the event payload
wile44 Jan 17, 2024
c5fb12c
Add response message if missing import summary
BaharaJr Jan 17, 2024
47d21d8
isolate enrollment payload from the main payload
wile44 Jan 17, 2024
4fc44ac
Merge branch 'develop' of https://github.com/udsm-dhis2-lab/d2-touch …
wile44 Jan 17, 2024
e6fc2d9
Upload enrollments separate on error 500
BaharaJr Jan 17, 2024
b39549c
Remove unused comments
BaharaJr Jan 19, 2024
18bccd5
Trim double quotes in values
BaharaJr Jan 22, 2024
a8388e8
add delete functuon in httpclient module
wile44 Jan 23, 2024
e70889e
add online deletion functionality
wile44 Jan 23, 2024
7b63c7d
Return empty string for missing resource name in api response
BaharaJr Jan 26, 2024
a6e4319
Check if ou has parent on download children
BaharaJr Jan 26, 2024
70a6de7
Get enrollment status from enrollment response
BaharaJr Jan 26, 2024
7357587
remove print statements
wile44 Jan 29, 2024
bee4276
Merge branch 'develop' of https://github.com/udsm-dhis2-lab/d2-touch …
wile44 Jan 29, 2024
edc2ce0
Add functionality for user fields selection on download
BaharaJr Jan 30, 2024
349029a
Fix critical issues in packages by upgrading and handling deprecated …
BaharaJr Jan 30, 2024
7492d85
Improve fields selection by passing the base fields prop in url gener…
BaharaJr Jan 30, 2024
854bd80
Use a different field for user selected fields to avoid conflicts
BaharaJr Jan 30, 2024
86a7e5e
Improve performance by removing save call on no data
BaharaJr Jan 31, 2024
833961c
Retain time stamps for created and updated fields
BaharaJr Jan 31, 2024
f35d30c
Remove hardcoded program status
BaharaJr Jan 31, 2024
d8c92e8
Improve insert performance by wrapping in try catch
BaharaJr Jan 31, 2024
17f2322
Fix failing tests by initiating a new database for each test
BaharaJr Jan 31, 2024
af2d390
Add saved attribute to tracked entity and event data
BaharaJr Feb 1, 2024
c0a4853
Add default import summaries for uknown network errors
BaharaJr Feb 1, 2024
d624662
Add checks for availability of respons body before getting resource
BaharaJr Feb 1, 2024
532119a
Fix error in updating value when last updated is missing
BaharaJr Feb 7, 2024
83471f2
Disable checks on data change
BaharaJr Feb 9, 2024
acc0024
Add checks on dynamic data to check for possible null values
BaharaJr Feb 9, 2024
7165735
Retain last updated checks
BaharaJr Feb 13, 2024
f3034dc
Bump SDK version
BaharaJr Feb 13, 2024
73d9e33
Set last updated value if missing
BaharaJr Feb 15, 2024
537f7ea
Add checks for event import responses
BaharaJr Feb 23, 2024
a54e5d6
Fix error saving dataValueSets for missing filters
BaharaJr Mar 14, 2024
ef42b97
Add functionality to get user authorities from userRoles
BaharaJr Mar 20, 2024
1b238a7
transform time format to that of the dhis2
wile44 May 2, 2024
d09a809
fix: format eventDate to meet DHIS2 standards
wile44 May 3, 2024
369d25b
Add fallbacks for mandatory fields in tracker
BaharaJr May 7, 2024
166f4f0
Remove unused lines of code
BaharaJr May 7, 2024
2e0c025
Add program rule expression execution for arithmetics
BaharaJr May 14, 2024
fc74ab1
Wrap tracker rule in a try catch block for uncaught errors
BaharaJr May 16, 2024
3b538c8
Map through actions to return json instead of instance of ProgramRule…
BaharaJr Jun 3, 2024
e25727d
Add functionality to re-evaluate math expressions for not operators
BaharaJr Jun 3, 2024
f44d93e
Add option and section to program rule entity
BaharaJr Jun 3, 2024
b64bdb5
Add JSON column type in column enum definition
BaharaJr Jun 3, 2024
87f87ef
Set dataview ou as encoded json on save
BaharaJr Jun 3, 2024
fb9c11d
Remove white spaces and AND in final dhis2 url
BaharaJr Jun 3, 2024
2d3c3a2
Fix error saving relationships
BaharaJr Jun 4, 2024
3ba20ec
Add section and option to program rule variable
BaharaJr Jun 5, 2024
5cbc627
release: Add option group column to program rule action
BaharaJr Jun 5, 2024
2ae6aee
Add option group module
BaharaJr Jun 5, 2024
6215efc
Add d2 evaluation and parsing date objects
BaharaJr Jul 23, 2024
d253269
feat: add delete function in httpClient
wile44 Aug 9, 2024
0270da1
Fix error on type of user organisations in user entity
BaharaJr Sep 4, 2024
a1cc3d1
Bump SDK version to 1.1.4
BaharaJr Sep 4, 2024
816e290
feat: add put function in httpClient
wile44 Sep 9, 2024
6fd8c39
feat: add configuration to publish in pub.dev
wile44 Sep 18, 2024
935491e
Improve runtime type checking for values in user orgunit model
BaharaJr Sep 4, 2024
aa26ea9
Add timestamp to check token expiry time
BaharaJr Sep 20, 2024
89bf0f2
Add timestamp to check token expiry time
BaharaJr Sep 20, 2024
2c18479
Add ApiToken grant type
BaharaJr Oct 14, 2024
3f66ac4
Bump SDK version to 1.1.8 with personal access tokens
BaharaJr Oct 14, 2024
eb54ba9
feat: update intl version from 18 to 19
wile44 Nov 17, 2024
af8517c
feat: make condition attribute nullable
wile44 Dec 4, 2024
f68280b
feat: make sortOrder attribute nullable
wile44 Dec 4, 2024
bbee409
feat: make dirty attribute not null
wile44 Dec 4, 2024
9725945
feat: change version of the package
wile44 Dec 4, 2024
f312e85
Bump intl package to version 0.19.0
BaharaJr Jan 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: PUBLISH

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+*"

jobs:
publish:
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
# with:
# working-directory: path/to/package/within/repository
31 changes: 31 additions & 0 deletions .github/workflows/task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: TASK
on:
pull_request:
branches:
- release
push:
branches: [develop]

jobs:
TASK:
if: |
github.event_name == 'push'
name: TASK
continue-on-error: true
runs-on: ubuntu-latest
steps:
- name: 🔄
uses: actions/checkout@v3
with:
ref: ${{ github.event.push.head.sha }}

- uses: BaharaJr/[email protected]
with:
CLICKUP_TOKEN: ${{secrets.CLICKTOKEN}}
LIST_ID: ${{secrets.LIST_ID}}
TASK_STATUS: ${{secrets.STATUS}}
ASSIGNEES: ${{secrets.ASSIGNEES}}
FIELDS: ${{secrets.FIELDS}}
MESSAGE: ${{github.event.head_commit.message}}
AUTHOR: ${{ github.event.commits[0].author.username ||
github.event.commits[0].author.login }}
77 changes: 77 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
## [1.1.9] 04/12/2024

- Add nullable support in program module
- Improve perfomance

## [1.1.8] 14/10/2024 - Happy Nyerere Day

- Add APiToken grant type to HTTP requests for personal access tokens

## [1.1.7] 20/09/2024

- Add timestamp to check token expiry time
- Add implementation to renew tokens on expiry

## [1.1.6] - 09/09/2024

- Add put method in httpClient

## [1.1.5] 04/09/2024

- Improve runtime type checking for values in user orgunit model
- Add fallback for dirty value

## [1.1.4] 04/09/2024

- Fix error on type of user organisations in user entity

## [1.1.3] - 09/08/2024

- Add delete function in httpClient
- Add d2 evaluation and parsing date objects
- Add option group module
- Add option group column to program rule action
- Fix error saving relationships
- Add functionality to re-evaluate math expressions for not operators
- Add program rule expression execution for arithmetics
- Fix error saving dataValueSets for missing filters

## [1.1.2] - 13/02/2024

- Add checks on dynamic data to check for possible null values
- Add checks for availability of response body before getting resource
- Add saved attribute to tracked entity and event data
- Add default import summaries for uknown network errors
- Improve insert performance by wrapping in try catch
- Remove hardcoded program status
- Use a different field for user selected fields to avoid conflicts
- Add functionality for user fields selection on download

## [1.1.1] - 07/08/2023

- Add support to upload relationships when uploading tracker entity instances

## [1.1.0] - 06/08/2023

- Add support to download program relationships
- Add support to donwload and upload tracker relationships
- Fix issue on clearing of shared preference on log out
- Fix data synchronization issues when local data is in dirty state

### Fixes

- Improve events program rules queueing on failing rules response
- Fix error with missing code column in user authority

## [1.0.3] - 23/03/2023

### Fixes

- Improve events program rules queueing on failing rules response
- Fix error with missing code column in user authority

### New

- Add job title and phone number properties to user entity
- Add data store module

## [1.0.2] - 17/09/2022

## [1.0.0-beta.13] - 09/09/2022
Expand Down
2 changes: 1 addition & 1 deletion database_builder.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
flutter packages pub run build_runner build --delete-conflicting-outputs
flutter pub cache clean && flutter pub get && flutter packages pub run build_runner build --delete-conflicting-outputs
8 changes: 7 additions & 1 deletion lib/core/annotations/column.annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:reflectable/reflectable.dart';

import 'entity.annotation.dart';

enum ColumnType { TEXT, INTEGER, BOOLEAN }
enum ColumnType { TEXT, INTEGER, BOOLEAN, JSON }

enum RelationType { OneToMany, ManyToOne, OneToOne }

Expand Down Expand Up @@ -75,6 +75,8 @@ class Column {
return 'INTEGER';
case ColumnType.BOOLEAN:
return 'BOOLEAN';
case ColumnType.JSON:
return 'JSON';
default:
return 'TEXT';
}
Expand All @@ -95,6 +97,10 @@ class Column {

static Column? getColumn(VariableMirror variableMirror, String columnName,
bool ignoreRelationColumns) {
if (variableMirror.metadata.isEmpty) {
return null;
}

dynamic variableElement = variableMirror.metadata[0];

if (variableElement is Column || variableElement is PrimaryColumn) {
Expand Down
20 changes: 12 additions & 8 deletions lib/core/annotations/entity.annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ class Entity {

if (value is VariableMirror) {
VariableMirror variableMirror = value;
Column column =
Column.getColumn(variableMirror, key, ignoreRelationColumns)
as Column;
columns.add(column);
Column? column =
Column.getColumn(variableMirror, key, ignoreRelationColumns);

if (column != null) {
columns.add(column);
}
}
}

Expand All @@ -63,10 +65,12 @@ class Entity {

if (value is VariableMirror) {
VariableMirror variableMirror = value;
Column column =
Column.getColumn(variableMirror, key, ignoreRelationColumns)
as Column;
columns.add(column);
Column? column =
Column.getColumn(variableMirror, key, ignoreRelationColumns);

if (column != null) {
columns.add(column);
}
}
}

Expand Down
31 changes: 31 additions & 0 deletions lib/core/database/database.util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:flutter/cupertino.dart';
import 'package:shared_preferences/shared_preferences.dart';

class DatabaseUtil {
/**
* Get database name form shared preferences
*/
static Future<String?> getDatabaseName(
{Future<SharedPreferences>? sharedPreferenceInstance}) async {
WidgetsFlutterBinding.ensureInitialized();
SharedPreferences prefs =
await (sharedPreferenceInstance ?? SharedPreferences.getInstance());
return prefs.getString('databaseName');
}

/**
* Set database name into the shared preferences
*/
static Future<bool> setDatabaseName(
{required String databaseName,
required SharedPreferences sharedPreferenceInstance}) async {
return sharedPreferenceInstance.setString('databaseName', databaseName);
}

static Future<void> removeDatabaseName(
{Future<SharedPreferences>? sharedPreferenceInstance}) async {
SharedPreferences prefs =
await (sharedPreferenceInstance ?? SharedPreferences.getInstance());
await prefs.remove('databaseName');
}
}
44 changes: 30 additions & 14 deletions lib/core/database/database_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class DatabaseManager {
bool inMemory = false;
DatabaseFactory? databaseFactory;

static final DatabaseManager _databaseInstance =
new DatabaseManager._internal();
static DatabaseManager? _databaseInstance;

static Database? _database;
final _initDatabaseMemoizer = AsyncMemoizer<Database>();
Expand All @@ -22,22 +21,25 @@ class DatabaseManager {
{String? databaseName,
bool? inMemory,
DatabaseFactory? databaseFactory}) {
if (databaseName != null) {
_databaseInstance.databaseName = databaseName;
}
if (_databaseInstance == null) {
_databaseInstance = new DatabaseManager._internal();
if (databaseName != null) {
_databaseInstance?.databaseName = databaseName;
}

if (inMemory != null) {
_databaseInstance.inMemory = inMemory;
}
if (inMemory != null) {
_databaseInstance?.inMemory = inMemory;
}

_databaseInstance.databaseFactory = databaseFactory;
_databaseInstance?.databaseFactory = databaseFactory;
}

return _databaseInstance;
return _databaseInstance as DatabaseManager;
}

DatabaseManager._internal();

static DatabaseManager get instance => _databaseInstance;
static DatabaseManager? get instance => _databaseInstance;

Future<Database> get database async {
if (_database != null) {
Expand All @@ -50,8 +52,14 @@ class DatabaseManager {
}

initializeDatabase() async {
if (this.databaseFactory != null) {
return databaseFactory?.openDatabase(inMemoryDatabasePath);
if (databaseFactory != null) {
bool databaseExist = await databaseFactory!.databaseExists(databaseName);

if (databaseExist) {
await databaseFactory?.deleteDatabase(databaseName);
}
return databaseFactory?.openDatabase(databaseName,
options: OpenDatabaseOptions(onConfigure: _onConfigure));
}

Directory documentDirectory = await getApplicationDocumentsDirectory();
Expand All @@ -72,7 +80,15 @@ class DatabaseManager {
await db.execute("PRAGMA foreign_keys = OFF");
}

closeDatabase() {}
closeDatabase() async {
await _database?.close();
}

dispose() async {
await _database?.close();
await databaseFactory?.deleteDatabase(databaseName);
_databaseInstance = null;
}

void _createDatabase(Database database, int version) async {}
}
21 changes: 21 additions & 0 deletions lib/core/models/d2_touch.model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:d2_touch/core/database/database_manager.dart';
import 'package:d2_touch/modules/auth/user.module.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sqflite/sqflite.dart';

abstract class D2TouchModel {
String locale = 'en';
bool? inMemory;
DatabaseFactory? databaseFactory;
late SharedPreferences sharedPreferenceInstance;
DatabaseManager? databaseInstance;

Future<DatabaseManager> setDatabase({
required String databaseName,
bool? inMemory,
DatabaseFactory? databaseFactory,
required SharedPreferences sharedPreferenceInstance,
});

UserModule get userModule;
}
File renamed without changes.
Loading
Loading