In this paper, a spacetime meshless method utilizing Trefftz functions for modeling subsurface flow problems with a transient moving boundary is proposed. The subsurface flow problem with a transient moving boundary is governed by the two-dimensional diffusion equation, where the position of the moving boundary is previously unknown. We solve the subsurface flow problems based on the Trefftz method, in which the Trefftz basis functions are obtained from the general solutions using the separation of variables. The solutions of the governing equation are then approximated numerically by the superposition theorem using the basis functions, which match the data at the spacetime boundary collocation points. Because the proposed basis functions fully satisfy the diffusion equation, arbitrary nodes are collocated only on the spacetime boundaries for the discretization of the domain. The iterative scheme has to be used for solving the moving boundaries because the transient moving boundary problems exhibit nonlinear characteristics. Numerical examples, including harmonic and non-harmonic boundary conditions, are carried out to validate the method. Results illustrate that our method may acquire field solutions with high accuracy. It is also found that the method is advantageous for solving inverse problems as well. Finally, comparing with those obtained from the method of fundamental solutions, we may obtain the accurate location of the nonlinear moving boundary for transient problems using the spacetime meshless method with the iterative scheme.