The verb itself controls the case of one or more nouns, pronouns or related phrases. For a typical verb this means the subject (nominative) and possibly a accusative object and/or a dative object. Which combination of objects depends on the verb and often its meaning. On top of this basic structure you can add prepositional phrases, meaning a preposition followed by phrase meaning a person or thing. The phrase following a preposition is sometimes called a prepositional object. The case of the prepositional object is determined by the preposition, but the scope of the preposition ends with the prepositional object and doesn't affect the other objects which may be present in the sentence.
For example:
Ich gebe dem Kind einen Kuchen in der Küche.
The basic sentence is
Ich gebe dem Kind einen Kuchen.
The verb here is geben (to give) which, in addition to the subject, expects an accusative object and a dative object. The accusative object is the thing being given, in this case einen Kuchen (a cake). The dative object is who is receiving what is being given, in this case dem Kind (the child). The prepositional phrase is added to the basic sentence but is not necessary for it. In this case the preposition is in which requires the dative. (The case used with in depends on the meaning; this is a separate issue which has been covered elsewhere on this site, but the simplified version is to use dative when it means "in" in English, and the accusative when means "into" in English.) The prepositional object here is der Küche (the kitchen), in the dative.
What you need to know is that prepositional phrases can (in principle) be added and removed without affecting the cases of the other objects in the sentence. The case of an object within a prepositional phrase depends on the preposition (and sometimes its meaning).
Remember that sentences can have many objects, and the case of each one must be determined individually depending on its role the the sentence. Up to two objects can be attached to the verb, and their cases can tell you how they are related to the verb. Other objects are connected to the sentence by prepositions, and their cases mostly determined by which preposition is being used with that object.