Liter is the American version while litre is the British version of the word.
Objectively, both of these words are the correct spelling. It simply depends on what region the English comes from.
I think then if you want to be strict about your writing style then you should just keep in mind where the majority of your readers are from.
The only reason your spellcheck prefers "litre" over "liter" is because itâ€™s English language system is based on British English and not American.
It doesnâ€™t really matter which of these two spellings you use, I would just be consistent with whatever one you decide to use in whatever you write about.
After all, they are just two words that describe a measurement of the metric system, which is of course the most important part.