It's not really complicated. Some prepositions always
use Dativ (for example, ab, aus, außer, bei, entgegen, entsprechend, mit, nach, seit, von or zu) that means that every time you see one of them you are going to find a dativ afterwards.
Then you have the Wechselpräpositionen. They are an, auf, hinter, in, neben, über, unter, vor and zwischen. If you are using them for describing a movement you use Akkusativ, and if you use them for describing a location you use Dativ.
That's the basics. There are a few things more but for starting, that'S more than enough
Basically, think about Akkusativ as the object of the action and the dative as the receiver of the action