This is a very old debate in the world of writing educational resources.
In the Society of Authors’ magazine The Author, Winter 2006 issue, Jenny Vaughan said, amongst other things, you should ensure you’re not being taken advantage of. This is good advice. It is so easy for new authors to undersell themselves. However, both forms of payment have their advantages and disadvantages.
On the plus side, flat rate fees are very useful as you can receive an often vital income quickly, whereas royalties provide a more long-term gain. But sometimes, you can spend ages writing a book, which is to be paid by royalties only and have very little come back if it does not sell well. whereas, with flat rate fees it often means you sign your rights away and you are usually writing to a very specific and tight brief.
Remember you should re-negotiate your fee on second editions. The publisher should pay a top-up fee and you should check the rights revert back to the author if the book goes out of print. The NUJ provides a very useful Freelance Fees Guide