How horrible for you, he certainly doesn’t sound as though he would be able to care for your dog. Lots of good advice from others about the RSPCA, Dogs Trust, free advice from solicitor, etc.
A word of warning. A friend divorced her husband and out of sheer spite he took their two cats because he had paid for them several years earlier. A huge row erupted just as the cats were taken out of her house and the police were involved. All extremely unpleasant, and at least one caution issued by the police, not to the ex husband but to someone helping him.
I don’t think my friend contested her ex-husband taking the cats or sought legal advice beforehand.
Do hope your lovely dog stays with you. ?