Compare commits
4 Commits
ab9b3e0bf9
...
8e6b574023
Author | SHA1 | Date | |
---|---|---|---|
8e6b574023 | |||
fcf4fca33b | |||
0aa8fdf271 | |||
3bf3dd3190 |
33
lib/db.dart
33
lib/db.dart
@ -24,8 +24,9 @@ class DatabaseHelper {
|
||||
String path = join(documentsDirectory.path, "com_hyperling_expense.db");
|
||||
return await openDatabase(
|
||||
path,
|
||||
version: 1,
|
||||
version: 2,
|
||||
onCreate: _onCreate,
|
||||
onUpgrade: _onUpgrade,
|
||||
);
|
||||
}
|
||||
|
||||
@ -41,6 +42,29 @@ class DatabaseHelper {
|
||||
""");
|
||||
}
|
||||
|
||||
Future _onUpgrade(Database db, int previousVersion, int newVersion) async {
|
||||
// Added in DB version 2.
|
||||
if (previousVersion < 2 && newVersion >= 2) {
|
||||
await db.execute("""
|
||||
CREATE TABLE income
|
||||
( id INTEGER PRIMARY KEY
|
||||
, name TEXT NOT NULL UNIQUE
|
||||
, revenue DOUBLE NOT NULL
|
||||
, frequency TEXT NOT NULL
|
||||
, description TEXT
|
||||
)
|
||||
""");
|
||||
await db.execute("""
|
||||
CREATE TABLE asset
|
||||
( id INTEGER PRIMARY KEY
|
||||
, name TEXT NOT NULL UNIQUE
|
||||
, amount DOUBLE NOT NULL
|
||||
, description TEXT
|
||||
)
|
||||
""");
|
||||
}
|
||||
}
|
||||
|
||||
/// Expense Section
|
||||
///
|
||||
Future<List<Expense>> getExpenses() async {
|
||||
@ -81,8 +105,11 @@ class DatabaseHelper {
|
||||
|
||||
Future<bool> checkExpenseNameExists(String name) async {
|
||||
Database db = await instance.db;
|
||||
var expenses = await db.query("expense",
|
||||
where: "name = ?", whereArgs: [name],);
|
||||
var expenses = await db.query(
|
||||
"expense",
|
||||
where: "name = ?",
|
||||
whereArgs: [name],
|
||||
);
|
||||
return expenses.isNotEmpty;
|
||||
}
|
||||
|
||||
|
19
lib/models/asset.dart
Normal file
19
lib/models/asset.dart
Normal file
@ -0,0 +1,19 @@
|
||||
import '/models/tracked_type.dart';
|
||||
|
||||
class Asset extends TrackedType {
|
||||
static String amountText = "Amount";
|
||||
|
||||
Asset({
|
||||
super.id,
|
||||
required super.name,
|
||||
required super.amount,
|
||||
required super.description,
|
||||
});
|
||||
|
||||
factory Asset.fromMap(Map<String, dynamic> json) => Asset(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
amount: json['amount'],
|
||||
description: json['description'],
|
||||
);
|
||||
}
|
@ -21,4 +21,15 @@ class Expense extends RecurringTrackedType {
|
||||
.first,
|
||||
description: json['description'],
|
||||
);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'cost': amount,
|
||||
'frequency': frequency.title,
|
||||
'description': description,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
35
lib/models/income.dart
Normal file
35
lib/models/income.dart
Normal file
@ -0,0 +1,35 @@
|
||||
import '/models/recurring_tracked_type.dart';
|
||||
import '/models/frequency.dart';
|
||||
|
||||
class Income extends RecurringTrackedType {
|
||||
static String amountText = "Revenue";
|
||||
|
||||
Income({
|
||||
super.id,
|
||||
required super.name,
|
||||
required super.amount,
|
||||
required super.frequency,
|
||||
required super.description,
|
||||
});
|
||||
|
||||
factory Income.fromMap(Map<String, dynamic> json) => Income(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
amount: json['revenue'],
|
||||
frequency: Frequency.values
|
||||
.where((freq) => freq.title == json['frequency'])
|
||||
.first,
|
||||
description: json['description'],
|
||||
);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'revenue': amount,
|
||||
'frequency': frequency.title,
|
||||
'description': description,
|
||||
};
|
||||
}
|
||||
}
|
@ -289,15 +289,15 @@ class _ExpenseInputDialogState extends State<ExpenseInputDialog> {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "${Expense.amountText} must be provided.";
|
||||
}
|
||||
if (double.tryParse(value) == null) {
|
||||
return "${Expense.amountText} must be a valid number.";
|
||||
}
|
||||
if (double.parse(value) < 0) {
|
||||
return "Please use the Income page rather than having negative expenses.";
|
||||
}
|
||||
if (double.parse(value) < 0.01) {
|
||||
return "${Expense.amountText} must be one hundreth (0.01) or higher.";
|
||||
}
|
||||
if (double.tryParse(value) == null) {
|
||||
return "${Expense.amountText} must be a valid number.";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user