Supposedly, if it hasn’t set seed yet then the leaves won’t have lost any flavor.
Flowering is a step in the process of “bolting” or “running to seed”, which plants try to do after they mature. But you want to keep the plant in “growth mode” where it’s vigorously putting out leaves.
Taste the leaves and see if they still have lots of good basil flavor. If so, then cut off the flower heads with about an inch of stem, and keep harvesting the leaves to discourage future flowering. (If they don’t, then just rip up and discard the plant. Or else let it run its course, if you think the flowers are pretty and/or you’d like to save seed from it. Basil is easier to propagate from cuttings than from seed; on the other hand, seeds don’t have to be fussed over or kept alive during the winter.)
And when you harvest the leaves, take off the whole clump of leaves and a good portion of stalk with them, don’t just pick individual leaves off the stem. (My mother cannot seem to learn this, and continually wonders why her basil plants get all leggy and leafless instead of staying nice and bushy. Just picking off the leaves one by one doesn’t keep the plant in growth mode.)
I’ve never noticed a dramatic difference in the taste of the leaves pre- and mid-flowering (i always nip them in the bud before they’ve all gone to flower), especially when I use the leaves in tomato sauce or pesto. You can also use the flowers themselves in some recipes, like basil iced tea and herb vinegar.