Stretching is good, I do the US Army "Daily dozen".
Calf cramps were very common in ROTC camp summer of '69, the sergeants said it was lack of potassium. Salt pills were handed out; many trainees took 6 to 10 a day, I took one. My cramps stopped.
Sports drink like "gatoraide" used to contain useful levels of potassium, but in the culture of more is better and drinking a gallon of gatoraide a day, the potassium content has been drastically lowered. Sports drinks now are mostly sugar. I did drink a gallon of WATER a day the summer I unloaded trucks in the Houston heat, but not gatoraide. I used to sweat my jeans soaking wet, that summer.
Bananas a nice way to get potassium if they don't make you vomit (which they do me). Bananas go stale awfully fast, and you have to buy them fresh on the weekly grocery trip whether the weather is hot and dry (causing sweating) or cold and rainy, causing indoor activities with no potassium excretion.
Physicians are a lot more worried now about "potassium poisoning" than about leg cramps, so it is difficult to get a physician to recommend pottassium supplements. In view of the 10 salt pills a day, or the gallons of gatoraide drunk by "real men", I would refuse to give advice to the testosterone poisoned, either. I hear the stupidist "training" handed out down at the gym I joined this year, to keep my winter slump from being quite as bad as last year. These trainers are professionals? I think I got better advice in the Army. Bulking up is stupid IMHO, amazing weightlifting feats are for men who intend to sit in front of a TV after age 35, whereas my goals are maintaining 70% of the strength I had in my younger days (I'm 63), keeping my stomach small and my gluteals padded, and exercising my heart enough to prevent symptoms common in American males. (sudden death, heart attacks, heart pains, stents, blockages).
Now when I get leg cramps in the summer (when I ride 70 miles per week on the bicycle plus carry trash cans of limbs to the sinkhole for several hours a day) I put a sprinkle of Morton's "lite salt" which is 50% potassium chloride on my food. One or twice a week a sprinkle, not every meal. I use no extra sodium salt at all. I get plenty of sodium from canned chili or microwave beef stew etc. It is hard to avoid sodium, which didn't used to bother me but since age 62 can cause a 4 psi surge in blood pressure if I eat 5 grams of sodium (TGI Friday's Potato Skins cheddar & bacon flavor is my vice of choice these days, along with liters of RC Diet Rite cola, which is apparenbly harmless).
I can also get calf cramps in the right leg only from sleeping on my back on a pillow. I view this as possibly caused by a collapsing disk, I refuse to talk to a doctor about it. My Mother was treated for collapsed disk: the surgery caused her great pain every day of the remainder of her life, and the muscle relaxant pills ruined her near vision. So this is a case of the possible cures being worse than the disease, IMHO. I sleep on my side to eliminate this cramp.