Yes. Assuming that you mean in an airplane, (jk) whether you can fly depends on whether the pericarditis is stable. If you had developed a large pericardial effusion, (fluid around the heart) for instance, you might not be stable to fly or even to leave a hospital. But if you just have benign pericarditis with a little chest pain, you could be stable.
As passenger. Preferably after diagnosis, and treatment.