I had to declare bankruptcy years ago for a couple of reasons, I have been financially stable for many years now, but I don't know if I can afford a home yet.
It is possible to take out a mortgage after filing bankruptcy. It will have to have been at least two or three years and you will have had to have been financially responsible since the bankruptcy. You will also probably need a larger down payment then you would have if you had never filed.
If you can take out a mortgage if you have been declared bankrupt but only with a limited number of lenders. Generally the interest rate will be higher than the standard home loan and there may be higher account keeping fees. This costs are higher as they are lending to borrowers who have highers chances of defaulting on their loan.
Lenders consider many factors. You might discuss the situation with a real estate professional after you organize your finances and know how much you can afford.