Sounds like we are married to the same guy. My H can turn his feelings on and off like a light switch.
Take it from me, do not cry, plea or beg him to stay because that will only push him farther away. I did this for about two months, then I realize I needed to leave him alone. So I gave him time and space. After 6 weeks of no contact with me he called me out of the blue and wanted to have lunch. Then a couple of days later he wanted to spend the day with me. It's hard but you will need to detach. Let him feel what life will be like with you.
Take this time for yourself and work on yourself. Once I started to self reflect, I did not like the person that I became. So I started to work on myself. And he has noticed the changes. And if he nice to you and show some kind of affection, please do not read anything into that because once he realizes that he was doing that, he will be cold the next time he sees you.