Move testing to be a global variable and use it to control the debug output.
This commit is contained in:
parent
029ee8e9a8
commit
a5e10e26cc
25
lib/db.dart
25
lib/db.dart
@ -9,6 +9,7 @@ import 'package:path_provider/path_provider.dart';
|
|||||||
import 'package:sqflite/sqflite.dart';
|
import 'package:sqflite/sqflite.dart';
|
||||||
|
|
||||||
// Local
|
// Local
|
||||||
|
import "/globals.dart";
|
||||||
import '/models/expense.dart';
|
import '/models/expense.dart';
|
||||||
import '/models/income.dart';
|
import '/models/income.dart';
|
||||||
import '/models/asset.dart';
|
import '/models/asset.dart';
|
||||||
@ -89,18 +90,18 @@ class DatabaseHelper {
|
|||||||
/// Expense Section
|
/// Expense Section
|
||||||
///
|
///
|
||||||
Future<List<Expense>> getExpenses() async {
|
Future<List<Expense>> getExpenses() async {
|
||||||
debugPrint("getExpenses(): Accessing db.");
|
if (testing) debugPrint("getExpenses(): Accessing db.");
|
||||||
Database db = await instance.db;
|
Database db = await instance.db;
|
||||||
|
|
||||||
debugPrint("getExpenses(): Querying table.");
|
if (testing) debugPrint("getExpenses(): Querying table.");
|
||||||
var expenses = await db.query("expense", orderBy: "name");
|
var expenses = await db.query("expense", orderBy: "name");
|
||||||
|
|
||||||
debugPrint("getExpenses(): Putting into object list.");
|
if (testing) debugPrint("getExpenses(): Putting into object list.");
|
||||||
List<Expense> expenseList = expenses.isNotEmpty
|
List<Expense> expenseList = expenses.isNotEmpty
|
||||||
? expenses.map((c) => Expense.fromMap(c)).toList()
|
? expenses.map((c) => Expense.fromMap(c)).toList()
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
debugPrint("getExpenses(): Returning!");
|
if (testing) debugPrint("getExpenses(): Returning!");
|
||||||
return expenseList;
|
return expenseList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,18 +147,18 @@ class DatabaseHelper {
|
|||||||
/// Income Section
|
/// Income Section
|
||||||
///
|
///
|
||||||
Future<List<Income>> getIncomes() async {
|
Future<List<Income>> getIncomes() async {
|
||||||
debugPrint("getIncomes(): Accessing db.");
|
if (testing) debugPrint("getIncomes(): Accessing db.");
|
||||||
Database db = await instance.db;
|
Database db = await instance.db;
|
||||||
|
|
||||||
debugPrint("getIncomes(): Querying table.");
|
if (testing) debugPrint("getIncomes(): Querying table.");
|
||||||
var incomes = await db.query("income", orderBy: "name");
|
var incomes = await db.query("income", orderBy: "name");
|
||||||
|
|
||||||
debugPrint("getIncomes(): Putting into object list.");
|
if (testing) debugPrint("getIncomes(): Putting into object list.");
|
||||||
List<Income> incomeList = incomes.isNotEmpty
|
List<Income> incomeList = incomes.isNotEmpty
|
||||||
? incomes.map((c) => Income.fromMap(c)).toList()
|
? incomes.map((c) => Income.fromMap(c)).toList()
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
debugPrint("getIncomes(): Returning!");
|
if (testing) debugPrint("getIncomes(): Returning!");
|
||||||
return incomeList;
|
return incomeList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,17 +202,17 @@ class DatabaseHelper {
|
|||||||
///
|
///
|
||||||
/// Liquid Asset Section
|
/// Liquid Asset Section
|
||||||
Future<List<Asset>> getAssets() async {
|
Future<List<Asset>> getAssets() async {
|
||||||
debugPrint("getAssets(): Accessing db.");
|
if (testing) debugPrint("getAssets(): Accessing db.");
|
||||||
Database db = await instance.db;
|
Database db = await instance.db;
|
||||||
|
|
||||||
debugPrint("getAssets(): Querying table.");
|
if (testing) debugPrint("getAssets(): Querying table.");
|
||||||
var assets = await db.query("asset", orderBy: "name");
|
var assets = await db.query("asset", orderBy: "name");
|
||||||
|
|
||||||
debugPrint("getAssets(): Putting into object list.");
|
if (testing) debugPrint("getAssets(): Putting into object list.");
|
||||||
List<Asset> assetList =
|
List<Asset> assetList =
|
||||||
assets.isNotEmpty ? assets.map((c) => Asset.fromMap(c)).toList() : [];
|
assets.isNotEmpty ? assets.map((c) => Asset.fromMap(c)).toList() : [];
|
||||||
|
|
||||||
debugPrint("getAssets(): Returning!");
|
if (testing) debugPrint("getAssets(): Returning!");
|
||||||
return assetList;
|
return assetList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
lib/globals.dart
Normal file
1
lib/globals.dart
Normal file
@ -0,0 +1 @@
|
|||||||
|
const bool testing = true;
|
@ -2,6 +2,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
// Local
|
// Local
|
||||||
|
import '/globals.dart';
|
||||||
import '/pages/home.dart';
|
import '/pages/home.dart';
|
||||||
|
|
||||||
// SQLite
|
// SQLite
|
||||||
@ -10,8 +11,6 @@ import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
|||||||
import 'package:path/path.dart';
|
import 'package:path/path.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
const bool testing = false;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// I see no good explanations of why to use this other package yet, but
|
// I see no good explanations of why to use this other package yet, but
|
||||||
// trying this to see if it fixes the DB factory errors.
|
// trying this to see if it fixes the DB factory errors.
|
||||||
@ -24,6 +23,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
// Remove the DB and recreate it to test the Database Helper multiple times.
|
||||||
if (testing) {
|
if (testing) {
|
||||||
() async {
|
() async {
|
||||||
Directory documentsDirectory = await getApplicationDocumentsDirectory();
|
Directory documentsDirectory = await getApplicationDocumentsDirectory();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user