This is not a simple question to answer. Yes, God is love (1 John 4:8 and 16) and God is light and in Him is no darkness (1 John 1:5). In contrast, Scripture says the Devil comes to steal, kill, and destroy (John 10:10).
To fully understand the reason why God had to flood the earth, we need to understand what was the depth of the problem that He was facing in order to bring about the redemption of mankind.
We have two items that we think biblically handle this problem (question):
The other is a transcription of our audio teaching The “Sons of God” of Genesis 6. This transcription is an in-depth documentation of why God had to do what He did in flooding the earth.
We trust both of the links above will be a blessing to you!