Science's theory is that fruits are not a gift, but a bribe. Or, to put it another way, the plants have a deal going with the animals that consume the fruit, or that consume the nectar in the flower.
The deal is that the animals will carry some of the plant's seeds away to new places. In the case of flowers, the animal carries pollen to other flowers of the same species. They are paid for this service in food.

