1801, "a story of a house," from Scottish flat "floor or story of a house," from Old English flett "a dwelling, hall; floor, ground," from Proto-Germanic *flatja-, from suffixed form of PIE root *plat- "to spread." Meaning "floor or part of a floor set up as an apartment" is from 1824. Directly from flat (adj.) come the senses "level ground near water" (late 13c.); "a flat surface, the flat part of anything" (1374), and "low shoe" (1834).
<a href="https://www.etymonline.com/word/flats">Etymology of flats by etymonline</a>
Harper, D. (n.d.). Etymology of flats. Online Etymology Dictionary. Retrieved $(datetime), from https://www.etymonline.com/word/flats