You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.0 KiB
63 lines
2.0 KiB
1 year ago
|
import 'dart:async';
|
||
|
|
||
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
||
|
import 'package:siopas/models/asset_status_model.dart';
|
||
|
import 'package:http/http.dart' as http;
|
||
|
import 'package:internet_connection_checker/internet_connection_checker.dart';
|
||
|
import 'package:sqflite/sqflite.dart';
|
||
|
|
||
|
import '../../../migrations/databasehelper.dart';
|
||
|
|
||
|
class ControllerHome {
|
||
|
final conn = SqfliteDatabaseHelper.instance;
|
||
|
Future<int> getPeminjamanCount() async {
|
||
|
final dbClient = await conn.db;
|
||
|
final count = Sqflite.firstIntValue(await dbClient!
|
||
|
.query(SqfliteDatabaseHelper.peminjamanTable, columns: ['COUNT(*)']));
|
||
|
return count ?? 0;
|
||
|
}
|
||
|
|
||
|
Future<int> getPengembalianCount() async {
|
||
|
final dbClient = await conn.db;
|
||
|
final count = Sqflite.firstIntValue(
|
||
|
await dbClient!.query(SqfliteDatabaseHelper.pengembalianTable,
|
||
|
columns: ['COUNT(*)']),
|
||
|
);
|
||
|
return count ?? 0;
|
||
|
}
|
||
|
|
||
|
Future<int> getTransferCount() async {
|
||
|
final dbClient = await conn.db;
|
||
|
final count = Sqflite.firstIntValue(
|
||
|
await dbClient!.query(SqfliteDatabaseHelper.transferPetiTable,
|
||
|
columns: ['COUNT(*)']),
|
||
|
);
|
||
|
return count ?? 0;
|
||
|
}
|
||
|
|
||
|
static Future<bool> isInternet() async {
|
||
|
var connectivityResult = await (Connectivity().checkConnectivity());
|
||
|
if (connectivityResult == ConnectivityResult.mobile) {
|
||
|
if (await InternetConnectionChecker().hasConnection) {
|
||
|
print("Mobile data detected & internet connection confirmed.");
|
||
|
return true;
|
||
|
} else {
|
||
|
print('No internet :( Reason:');
|
||
|
return false;
|
||
|
}
|
||
|
} else if (connectivityResult == ConnectivityResult.wifi) {
|
||
|
if (await InternetConnectionChecker().hasConnection) {
|
||
|
print("wifi data detected & internet connection confirmed.");
|
||
|
return true;
|
||
|
} else {
|
||
|
print('No internet :( Reason:');
|
||
|
return false;
|
||
|
}
|
||
|
} else {
|
||
|
print(
|
||
|
"Neither mobile data nor WIFI detected, no internet connection found.");
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|