getTableRow static method
dynamic
getTableRow()
Implementation
static getTableRow() async {
loading.refresh((listener) => listener.value = true);
replacedFunction(
StackFunction(
id: 1,
function: () async {
await getRelation(withFunction: () async {
buildTableRow = [];
showedData = [];
selectColumn = [];
final getDataColumn = SQL.listTableDatabase.where((element) => element.tableName == SQL.selectedTable?.tableName);
TableDatabase? data;
if (getDataColumn.isNotEmpty) {
data = getDataColumn.first;
globalData = data;
}
if (data != null) {
final getQ = _dataMerge != null ? _dataMerge!.table(data.tableName).limit(double.parse(QueryController.limit.controller?.text ?? '50').floor()) : DB.table(data.tableName).limit(double.parse(QueryController.limit.controller?.text ?? '50').floor());
try {
if (QueryController.selectedFilterColumn != null) {
getQ.where(QueryController.selectedFilterColumn?.id, 'LIKE', '%${QueryController.search.controller!.text}%');
}
} catch (_) {}
final getData = await getQ.get();
maxData = getData.length;
for (var i in data.column) {
selectColumn.add(
SelectData(
id: i.name,
title: i.name,
),
);
if (i.primaryKey) {
for (var j in getData) {
showedData.add(j[i.name]);
}
}
final List<Widget> buildTableRowIn = [];
buildTableRowIn.add(
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
decoration: BoxDecoration(
color: const Color(0xffF8F8F8),
borderRadius: BorderRadius.circular(7),
border: Border.all(color: (currentForeignKey?.baseColumn != null && currentForeignKey?.baseColumn == i.name) ? Colors.green : Colors.black26, width: 1),
),
child: Row(
children: [
Expanded(child: Text(i.name)),
],
),
),
),
);
for (var j in getData) {
final ref = currentForeignKey?.referenceColumn;
buildTableRowIn.add(
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: GestureDetector(
onTap: () {
// print((currentForeignKey?.baseColumn != null && currentForeignKey?.baseColumn == i.name));
if ((currentForeignKey?.baseColumn != null && currentForeignKey?.baseColumn == i.name)) {
selectTable(dataTable.value.where((element) => element.tableName == currentForeignKey!.referenceTable).first, fillFunction: () {
QueryController.selectedFilterColumn = SelectData(
id: ref,
title: ref,
);
QueryController.search.controller!.text = j[i.name].toString();
});
}
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
decoration: BoxDecoration(
color: const Color(0xffF8F8F8),
borderRadius: BorderRadius.circular(7),
border: Border.all(color: (currentForeignKey?.baseColumn != null && currentForeignKey?.baseColumn == i.name) ? Colors.green : Colors.black26, width: 1),
),
child: Row(
children: [
Expanded(
child: Text(
j[i.name].toString(),
),
),
],
),
),
),
),
);
}
buildTableRow.add(
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: IntrinsicWidth(
child: Column(
children: buildTableRowIn.toList(),
),
),
),
);
}
}
dataTable.refresh((listener) => null);
loading.refresh((listener) => listener.value = false);
});
},
),
);
}