Portugal only had 2 reigning Queens D.Maria I and D.Maria II in the 18th and 19th century, but the first king got the throne via his mother, D.Teresa, daughter of the king of Castille, Leon and Galicia and Countess of Portugal by marriage in the early 12th century.
We could have had another queen in the 14th century, D.Beatriz, but she was married to the king of Castille and that led to the revolution that brought the Aviz dynasty to the throne.
D.Teresa's sister, Urraca, was Queen of Castille and Leon.
Followed Isabel the Catholic and Juana la Loca.
Instead of Isabel, there could have been Juana, Isabel's niece, but her paternity was disputed.
So, there was never a major issue as whether the heir was male or female although kings always prefer to have male heirs.