I have this same problem. I am not sure if medication will help but I really don't want to go there. My brain is a scattered mess. Even now, I am doing 3 other things at the same time. Is it a matter of "getting good" and just focus? I just don't think there's a secret technique to this.
I've struggled with this too. What's helping me is working to build mental habits and systems for how I approach the things I want to do. I suppose this is "getting good" but I don't think you can just brute force willpower your way through it
First decide specifically what you want to do, if it's even worth doing, and how long you expect it'll take. Set a timer for that time to focus on it. Once the timer goes off, reassess. Are you done? Should you continue? When you start getting distracted and veering off into something else, get up and take a breather away from any tech to reset.
Alongside that put small barriers up to protect your focus and make it as easy as possible. Turn notifications off. Put your phone in another room. Try something like Leechblock