
I wasted two days of mine to resolve this issue which occurs when you build IOS from flutter project.
Error Xcode: Flutter failed to write to a file
Error (Xcode): Flutter failed to write to a file at “~/
2/build/ios/Release-iphoneos/.last_build_id”.
This issue occurs due because cache and versions mismatch in dependencies while overriding a project from other systems.
I resolved issue from this answer on Stackoverflow.
Solution
You can resolve it with following steps:
Update your Xcode project build option
Because it will stop executing your user scripting before building project which causes this problem. The mismatch versions of your user/system causes this error.ENABLE_USER_SCRIPT_SANDBOXING
to ‘No’.

Thanks to Pratik.
Follow me on Medium.
For tips checkout my blogs here