You can't uniformly apply sunscreen on your entire body. Depending on type of skin, vitamin D will hit maximal daily production from sunlight in range of very fast to very slow.
So, yes, sunscreen might block some vitamin D production for some people, or might not do it at all.
Its perhaps prudent to apply it to some skin parts that are most affected by sunlight (face, shoulders) and leave other body parts without it. There you have benefits of both worlds.
Furthermore, vitamin D is not the only substance produced by the skin via sunlight (although we don't know much about other ones), so vitamin D from diet is not a substitute for it. Furthermore, vitamin D from diet can easily cause calcification depending on other factors (vitamin K and A in the diet and genetics) while there is internal protection for body made one.