-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
267 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import 'package:get_it/get_it.dart'; | ||
|
||
import 'providers/loan_provider.dart'; | ||
import 'services/database_service.dart'; | ||
|
||
final getIt = GetIt.instance; | ||
|
||
void setup() { | ||
getIt.registerSingleton<LoanProvider>(LoanProvider()); | ||
getIt.registerSingleton<DatabaseService>(DatabaseService()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
class Loan { | ||
int id; | ||
String description; | ||
double amount; | ||
DateTime date; | ||
|
||
Loan({this.description, this.amount}); | ||
Loan({this.id, this.description, this.amount, this.date}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:path/path.dart'; | ||
import 'package:sqflite/sqflite.dart'; | ||
|
||
class DatabaseService { | ||
DatabaseService() { | ||
Future(() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
_database = openDatabase( | ||
join(await getDatabasesPath(), 'cash_loaf_database.db'), | ||
onCreate: (db, version) { | ||
return Future.wait([ | ||
db.execute( | ||
"CREATE TABLE person(id INTEGER PRIMARY KEY, name TEXT)", | ||
), | ||
db.execute( | ||
"CREATE TABLE loan(id INTEGER PRIMARY KEY, description TEXT, amount REAL, date TEXT, person_id INTEGER NOT NULL, FOREIGN KEY (person_id) REFERENCES person (id))", | ||
) | ||
]); | ||
}, | ||
onOpen: (db) { | ||
return db.execute('DELETE FROM loan; DELETE FROM person;'); | ||
}, | ||
version: 1 | ||
); | ||
}); | ||
} | ||
|
||
Future<Database> _database; | ||
Future<Database> get database => _database; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.