First case: uncommanded flap retraction.
Before V1: abort (well, yeah. Obvious)
After V1: TOGA, depending on RWY length, selected VR and terrain situation: rotate at Vmu (clean) and do a shallow climb, slowly accelerating (my personal opinion)
Second case: uncommanded flap extension.
Most likely at cruise speed you'll lose your flaps... reduce speed to min clean anyway and plan for flaps up landing...