checkAndSyncPendingDetalles method

Future<void> checkAndSyncPendingDetalles()

Implementation

Future<void> checkAndSyncPendingDetalles() async {
  if (await Connectivity().checkConnectivity() == ConnectivityResult.none) {
    return;
  }

  final pending = await _dbHelper.getPendingDetalleEspecie();
  for (var record in pending) {
    final detalle = jsonDecode(record['data'] as String);
    final success = await uploadDetalle(detalle);
    if (success) {
      // record['id'] es int, así coincide con la firma
      await _dbHelper.deletePendingDetalleEspecie(record['id']);
      await _sendNotification(
        'Sincronización Exitosa',
        'Detalle sincronizado',
      );
    } else {
      await _sendNotification(
        'Fallo Sincronización',
        'No pudo sincronizar',
      );
      break;
    }
  }
}