- 花が好きだって聞いた。 (Google Translate)
- あなたが花が好きだって聞いたよ。 (Your attempt)
Both sentences are perfectly fine, at least grammatically. I don't know why you thought the first sentence is "wrong". Still, since your attempt is close to the original one, let me clarify the difference introduced by your addition of あなたが and よ.
It's a good idea to add よ at the end. Sentence 1 is not unnatural, but if you say this before you give a bouquet to someone, it may sound a little blunt, because of the lack of "emotion" added by sentence-end よ/ね/！/etc. Sentence 1 looks like this was said by a silent and introvert character in fiction. If you felt you wanted to use よ at the end, that's very good.
On the other hand, it's a bad idea to add あなたが. It's not just unnecessary, but it's harmful. Basically you should never use such a polite second-person pronoun when you talk to your close friend. The best approach is to omit the person pronoun because it can be inferred from the context.
Basically Google Translate is very bad at dealing with register, formality, keigo and role words. They do not know who you are and who you're talking/writing to, after all.