TLDR: Beat Brendan/May Gym Trainer in Petalburg City and go to Route 119.
You'll face off against Team Magma or Aqua at the Weather Institute. Win that, and there's still your rival, May or Brendan, waiting to challenge you. Triumph here and Fly is yours! But wait, there's a catch: to use Fly outside of battles, you need the Feather Badge from Winona in Fortree City. And don't forget, you need a Pokémon like Swellow, Pelipper, or Altaria – they're the ones who can actually learn Fly. Trust me, this HM is a game-changer for getting around Hoenn swiftly.
Source: RespawnFirst