I personally wouldn't. Especially a dog. We have dogs and cats and I honestly would not reccommend for a flat. We've had inside cats too in the past and again I still wouldn't reccommend in your scenario. If you really want a pet, then a bearded dragon or a rat would be a better call. One of my rats used to run mazes. Another used to just be with me ALL the time on my shoulder or up a sleeve. Used to come when called and slept in my bed! (I was a teenager at the time).
Please don't get a rabbit unless you are really 100% on their needs. They need a LOT of attention. After having rabbits for several years with a massive part of the garden fenced off for them, to see them dig tunnels (or just a lot of holes!), do massive bunny flips, chase each other, sunbathe etc. It's hard to think they'd ever be ok in a cage.
You can't guarantee a cat will be happy inside. You can try and choose a breed that would be more suitable (Ragdolls / Persians etc.) But they are all different at the end of the day and you won't know until you have one what personality you've got....so why risk it not working out and having to rehome? One of our cats is LOUD and I'm sure if we lived in flats we would have had complaints. One of our current cats hates the outside. She'll only come out with us.
On another note your pet needs to be able to have space without being invaded by your 2 year old. Have a good think if that's possible. One of my cats actively disappears when we have visiting children under 5 (although likes our children, 3 under 6!) The other LOVES children of any age. Again really my point is you don't know what your cat (or dog) will be like. Our 2 dogs are also very differnet. My retriever is pretty uninterested in our children (unless they have food...), whilst our terrier loves a cuddle. They both have their own space and I NEVER leave them unsupervised with the children. Ever. I put them behind a gate, giving them 1/2 the house we have visiting children under 8.
Also re: dog...our elderly dog needs letting out for a wee all the time. More than 3 hours and she's desperate. Think if you could manage this with your lifestyle. Our dogs are never left for more than 3 hours (4, 5 at a push when they were younger), is this something you can commit to? Again you'll have people say you can leave dogs all day etc. But that's not my experience, especially with an older fur baby.
Sorry OP. Good luck with bringing an animal into your life. It's a wonderful addition to a family, but please choose carefully. You'll get a variety of views and some cats / dogs may well be fine in a flat but I personally think you're running the risk of heartbreak. Good luck and best wishes :)