Before you read this, note that I am not familiar with the weaponry used outside of Europe, but this is what I know about the use of flails in the Middle Ages in Europe.
Flails were never very popular and fixed maces were always more desirable. If one-handed flails with spiky metal balls on chains were actually used in Medieval battles is still under debate. There are some depictions in medieval manuscripts of people carrying similar weapons, but these are still just illustrations. As far as I know there are very few examples of flails and a lot of the artifacts we have are somewhat dubious. A lot of them are forgeries from later periods, especially those with very long chains, which would have been pretty much useless in battle as the spiked ball would keep hitting your hand (even holding a flail with a short chains is quite difficult because of all that weight).
There is however a manual from 1836 by Capitaine de Bast, which references a 1736 (long after the Middle Ages) manual by Girard, which basically says that flails were only useful for attacking and they also say that it is quite dangerous for the user (you could actually kill yourself with it if you weren't strong enough). So using this kind of weapon in a packed formation on the battlefield would have been impossible.
The flail is thought to originate from the two-handed agricultural tool, used for whacking wheat. This type of agricultural flail is of course very different from the stereotypical one-handed shaft with a chain and spiky metal ball. The version that the peasants used was just a very long stick with a short chain or kind of rope linked to a shorter fatter stick. But because this was a common tool on a farm it was often seen in Late Medieval peasant revolts (like the German peasants' war), however this was still by no means more desirable than a fixed mace.
On the other hand, maces were very popular in the late Medieval period when armourers learned to make very good armour and a normal sword just wouldn't cut it anymore. Therefore maces, warhammers and polearms became the logical choice for many soldiers, simply because they could bash in even the best of the most modern plate armour.
Although the flail does give a bit more acceleration to the ball, a fixed mace is still far easier to wield, and that's why the wooden shaft with a spiked ball on a chain is something you see more often in fiction than in reality.
Don't forget that a flail was originally a tool for threshing grain, and it shares this distinction with other weapons-turned-tools, such as knives, scythes and sickles.
The first time someone used a flail in a violent setting was probably due to necessity, not because they thought "this will probably serve me better than a sword/mace/pollax".
Like the scythe (1) and the sickle (2), the flail was popular enough as a weapon to warrant inclusion in several fencing/fighting manuals, in fact a cursory search through Wikipedia and Wiktenauer shows more manuals that teach fighting with or against a flail:
So not a huge amount of material, but enough to give an impression that it wasn't unheard of to use flails in a civilian context and to give an idea about how to use it.
Notes: