It seems like this was a bug in Flutter. After an update to Flutter 3.27.2 3 days ago, the bug was gone.