Move testing to be a global variable and use it to control the debug output.

This commit is contained in:
Hyperling 2025-03-07 12:47:40 -07:00
parent 029ee8e9a8
commit a5e10e26cc
3 changed files with 16 additions and 14 deletions

View File

@ -9,6 +9,7 @@ import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart';
// Local
import "/globals.dart";
import '/models/expense.dart';
import '/models/income.dart';
import '/models/asset.dart';
@ -89,18 +90,18 @@ class DatabaseHelper {
/// Expense Section
///
Future<List<Expense>> getExpenses() async {
debugPrint("getExpenses(): Accessing db.");
if (testing) debugPrint("getExpenses(): Accessing db.");
Database db = await instance.db;
debugPrint("getExpenses(): Querying table.");
if (testing) debugPrint("getExpenses(): Querying table.");
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
? expenses.map((c) => Expense.fromMap(c)).toList()
: [];
debugPrint("getExpenses(): Returning!");
if (testing) debugPrint("getExpenses(): Returning!");
return expenseList;
}
@ -146,18 +147,18 @@ class DatabaseHelper {
/// Income Section
///
Future<List<Income>> getIncomes() async {
debugPrint("getIncomes(): Accessing db.");
if (testing) debugPrint("getIncomes(): Accessing db.");
Database db = await instance.db;
debugPrint("getIncomes(): Querying table.");
if (testing) debugPrint("getIncomes(): Querying table.");
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
? incomes.map((c) => Income.fromMap(c)).toList()
: [];
debugPrint("getIncomes(): Returning!");
if (testing) debugPrint("getIncomes(): Returning!");
return incomeList;
}
@ -201,17 +202,17 @@ class DatabaseHelper {
///
/// Liquid Asset Section
Future<List<Asset>> getAssets() async {
debugPrint("getAssets(): Accessing db.");
if (testing) debugPrint("getAssets(): Accessing db.");
Database db = await instance.db;
debugPrint("getAssets(): Querying table.");
if (testing) debugPrint("getAssets(): Querying table.");
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 =
assets.isNotEmpty ? assets.map((c) => Asset.fromMap(c)).toList() : [];
debugPrint("getAssets(): Returning!");
if (testing) debugPrint("getAssets(): Returning!");
return assetList;
}

1
lib/globals.dart Normal file
View File

@ -0,0 +1 @@
const bool testing = true;

View File

@ -2,6 +2,7 @@
import 'package:flutter/material.dart';
// Local
import '/globals.dart';
import '/pages/home.dart';
// SQLite
@ -10,8 +11,6 @@ import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
const bool testing = false;
void main() {
// 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.
@ -24,6 +23,7 @@ void main() {
}
WidgetsFlutterBinding.ensureInitialized();
// Remove the DB and recreate it to test the Database Helper multiple times.
if (testing) {
() async {
Directory documentsDirectory = await getApplicationDocumentsDirectory();