This paper presents an analytical solution for fluid flow and heat transfer inside arbitrarily-shaped triangular ducts for the first time. The former analytical solutions are limited to the special case of isosceles triangular ducts. The literature has no report about the analytical solution for the general case of arbitrarily-shaped triangular ducts. Due to the significant role of fluid flow through non-circular channels in industry and the large number of triangular shapes, a method for solving the heat transfer problem for all triangular shapes is needed. The heat transfer of a fluid flow through a channel with an arbitrary triangular cross-section for the case of constant heat flux at the walls is solved in this work for the first time, considering viscous dissipation. Here, the functionals of flow and heat transfer equations are derived, and the resulting Euler–Lagrange equations are solved using the Ritz method. The effect of the duct geometry on the velocity profile and friction coefficient is studied in detail. The effect of the Brinkman number on the temperature distribution and Nusselt number is investigated for both cooling and heating cases. The results reveal that the critical Brinkman Number distinguishes between the cooling and heating cases and represents the critical point at which the Nusselt number approaches infinity. The value of the Nusselt number decreases with the increase of the Brinkman number in both the wall cooling and heating modes. It is also found that the equilateral triangle exhibits the minimum friction coefficient and the maximum value of the Poiseuille number.