getItem static method

Future<StorageItem?> getItem(
  1. String id
)

Implementation

static Future<StorageItem?> getItem(String id) async {
  final db = await _openDb();
  final res = await db.query(
    PackageConfig.tableName,
    where: 'id = ?',
    whereArgs: [id],
  );
  if (res.isEmpty) return null;
  final row = res.first;
  final type = row['type'] as String;
  final Uint8List bytes = row['data'] as Uint8List;
  dynamic decoded;
  switch (type) {
    case 'json':
      decoded = jsonDecode(utf8.decode(bytes));
      break;
    case 'text':
      decoded = utf8.decode(bytes);
      break;
    case 'binary':
    case 'file':
    case 'blob':
      decoded = bytes;
      break;
    default:
      decoded = bytes;
  }
  return StorageItem(
    id: row['id'] as String,
    type: type,
    data: decoded,
    metadata: jsonDecode(row['metadata'] as String),
    createdAt: row['created_at'] as int,
  );
}