Exercise 1.2.9 in Qing Liu's Algebraic Geometry and Arithmetic Curves reads as follows:
Let $A$ be an integral domain and $K$ its field of fractions. Suppose $M \subset K$ is a finitely-generated $A$-submodule of $K$. Show that $M$ is flat iff it is locally free of rank $1$, i.e. for every prime $\mathfrak{p}$, $M_{\mathfrak{p}}$ is free of rank $1$ as an $A_{\mathfrak{p}}$-module.
A well-known lemma says that any finitely generated flat module over a local ring is free. Accordingly, $M_{\mathfrak{p}}$ is free as an $A_{\mathfrak{p}}$-module, say with free basis $\{x_1, \dots, x_d\}$. To show the rank is $1$, my guess is that we should find some $i$ such that $x_j/x_i \in A_{\mathfrak{p}}$ for all $j\neq i$, and then we are done. But I am not sure how to see this in general; if $A$ is a Dedekind domain, for example, we can just take $x_i$ to be the one with lowest $\mathfrak{p}$-adic valuation.
I am surely missing something simple. Any help would be very appreciated.
Hint:
Consider the $K$-vector space $M\otimes_A K$: if $M$ is locally free of rank $r$, $M\otimes_A K$ is a $K$-vector space of dimension $r$. But what is $M\otimes_A K$ equal to?