getBool method
Future
getBool(
- dynamic dbName
)
Implementation
Future<dynamic> getBool(dbName) async {
dynamic stringValue;
bool boolValue;
List<Map<String, dynamic>> allRows = [{}];
Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, "$dbName.db");
Database _database = await openDatabase(path, version: _databaseVersion,
onCreate: (Database db, int version) async {
await db.execute(
'CREATE TABLE ${dbName}1 (${dbName}_key INTEGER, $dbName INTEGER)');
});
Database db = _database;
var getValue;
getValue = Sqflite.firstIntValue(
await db.rawQuery('SELECT COUNT(*) FROM ${dbName}1'));
try {
allRows = await db.query(dbName + '1');
stringValue = allRows[getValue - 1][dbName];
if (stringValue == 1) {
boolValue = true;
print("$dbName value is $boolValue");
return boolValue;
} else {
boolValue = false;
print("$dbName value is $boolValue");
return boolValue;
}
} catch (exception) {
print("no data was found in $dbName");
return false;
}
}