It means “should have done something”. It is used for saying what was the right thing to do when you realize that someone didn’t do it. To emphasize regret or to blame the person who didn't do it, “~ばよかったのに” is often said. You can also use "~べきだった" instead.
日本で美容院に行った時、自分のやりたい髪型を説明するのが難しかった。日本語を、もっと一生懸命に勉強すればよかった。
- Meg: You look a little under the weather. What's wrong?
元気ないみたいだけど、大丈夫? - Ken: I've had this headache since I woke up. If I had taken a medicine, I would have been fine.
朝起きた時から、頭が痛いんだ。薬を飲めばよかった。
- Ken: Look. We're going to the restaurant over there.
見て。あそこのレストランに行くよ。 - Mei: Wow, it looks really fancy. You should've told me where we were going.
わぁー、高級レストランみたい。行き先を教えてくれればよかったのに。 - Ken: I wanted to surprise you. We should enjoy a meal in a good place once in a while.
驚かせようと思って。たまには、良い店で食事をしないとね。 - Mei: I would have put on a better dress if I had known you were taking me there.
ここに来るって知っていれば、もっといい服を着て来たのに。