This is always a though one and I usually just try to avoid it all together by just keeping walking because as has been said, sometimes you just don't know how it's going to go.
My Beagle has this strong sense about people, kids included. Once when I was about 21, single and childless

, I took her to a bar friends of mine owned (with their blessing of course) on Halloween because I had her in a doggie costume

. She was a huge hit of course and was great with everyone petting her. Then, after being petted about 30+ times by different people, this one lady reached out to pet her and Darla growled at her

. I think the lady wasn't very comfortable around dogs (you could kind of tell - she just had her hand reached out and stayed kind of back) and my dog knew it. Ever since then if someone asks to pet on a walk - I watch the dogs reactions to that person carefully first. If they go right up to the person curious and wanting the attention, I say sure. If they seem scared or just uninterested, I usually just say "oh - she's afraid of strangers" and if it's a kid I simply say "sorry honey, she might bite" and they quickly pull their hand back lol. I know that sounds mean but hey, it's not worth the risk -
our walks aren't a traveling petting zoo lol there's purpose to it and I like the dogs to just focus on "traveling".
Alice backs away from strangers on walks so that's easy lol, my Akita usually completely ignores them and most people are slightly scared to pet her in the first place cause she looks like a wolf lol and Darla's selective about people so it depends.