Right, you get a 5-minute time window by default - that might or might not last you for the whole sequence of commands here, according to how many packages / flatpaks need upgrading.
If you’d like to stick to the succession of commands instead of a script, given that for wheel users the flatpak update|remove commands don’t require sudo, you can reorder the commands and start with a sudo validation (for the cached credentials to be updated). That way you probably won’t be asked for another password entry.