Preheat the oven to 375 degrees.
Spray the bottoms and sides of an 8 x 8 baking dish with non-stick cooking spray.
Arrange one cup of the potatoes in the prepared baking dish, overlapping if necessary. Top the potatoes with one third of the onions, one third of the flour and sprinkle with kosher salt and pepper.
Repeat to make three layers in the baking dish.
Top with diced butter.
Heat the milk in a small saucepot to a simmer over medium heat.
Pour the hot milk over the potatoes in the baking dish.
Sprinkle with shredded cheese.
Bake, covered, until the potatoes are fork tender, about 55 minutes.
Uncover and bake until the cheese bubbles and browns, an additional 15 minutes.
If you want a crispier topping, remove the baking dish from the oven and preheat the broiler.
Place the baking dish about 4 inches from the heat source and broil for 1-2 minutes keeping a careful eye on it to be sure it doesn’t burn.
Remove the baking dish from the oven, and let it stand for 15 minutes. The sauce will thicken upon standing.
Sprinkle with parsley, if desired, before serving.