High fidelity computational modeling and optimization of aircraft has the potential to allow engineers to produce more efficient designs, requiring fewer unforeseen design modifications late in the design process. In order for the optimization algorithm to generate a useful design, all the relevant physics must be considered, including flutter. This is especially important for the high-fidelity aerostructural optimization of commercial aircraft, which is likely to result in wing designs that are prone to flutter. To address this issue, we develop a flutter constraint formulation suitable for gradient-based optimization. This paper investigates the feasibility of using a Doublet-Lattice Method (DLM) based flutter constraint for high-fidelity aerostructural optimization. An efficient non-iterative root finding method is developed to compute the flutter eigenvalues from a generalized eigenvalue problem, based on the p-k flutter equation. A mode tracking scheme is implemented at two levels that successfully tracks the mode migration. An effective constraint curve is then developed to define the flutter free flight envelope, in addition to preventing discontinuities in the flutter constraint. This method allows for minimum flutter velocity to be specified implicitly. The Kreisselmeier-Steinhauser (KS) function is used to aggregate the difference of the flutter damping eigenvalues and the constraint curve into a single value that is then used in an optimization. We compute accurate and efficient derivatives of the constraint value with respect to structural sizing variables, as well as wing planform variables. Derivatives are computed using a combination of analytic and automatic differentiation methods in reverse (adjoint) and validated using the complex-step method. To study the behavior of the flutter constraint using this method, we perform a design space analysis and optimize an idealized wing (flat plate) of a rectangular planform.