getEstimatedTotalSizeInMB method

Future<double> getEstimatedTotalSizeInMB()

Get the estimated total size of the database in MegaBytes

Implementation

Future<double> getEstimatedTotalSizeInMB() async {
  // We get the estimated size of the database in bytes
  // by summing the size of the gzipped json column and
  // the size of the barcode column and last update column
  final int? estimatedDataSize = Sqflite.firstIntValue(
    await localDatabase.database.rawQuery('''
      select sum(length($_TABLE_PRODUCT_COLUMN_BARCODE)) +
      sum(length($_TABLE_PRODUCT_COLUMN_LAST_UPDATE)) +
      sum(length($_TABLE_PRODUCT_COLUMN_LANGUAGE)) +
      sum(length($_TABLE_PRODUCT_COLUMN_GZIPPED_JSON))
      from $_TABLE_PRODUCT
      '''),
  );
  return double.parse(
    ((estimatedDataSize ?? 0) / ~1024 / ~1024).toStringAsFixed(2),
  );
}