You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iMac Flutter环境下lib/main.dart无法打开,求助打开方法

解决iMac上Flutter项目中main.dart显示为dmg图标无法打开的问题

Hey there, let's work through why your lib/main.dart file is showing up with a dmg icon and refusing to open on your iMac. This is almost always a file association hiccup or a small issue with the file's naming/type—here's how to fix it step by step:

  • First, double-check the file extension
    Open Finder, hit Cmd + , to pull up Preferences, then check the box for Show all filename extensions. Navigate to your Flutter project's lib folder and make sure the file is actually named main.dart—sometimes downloads or unzipping can sneak on hidden extensions like .dmg at the end (making it main.dart.dmg without you noticing). If that's the case, right-click the file → Get Info, edit the Name & Extension field to remove the extra .dmg, and confirm the change when prompted.

  • Force open it with the right app
    If the extension is correct but the icon is still wrong, right-click the file → Open With → Other. Pick your preferred code editor (VS Code, Android Studio, IntelliJ, or even TextEdit for a quick test) and check the box that says Always open with this app. Click Open—this will reset the system's default association for .dart files, and the icon should switch back to normal immediately.

  • Verify the file isn't corrupted
    If you just created the project or imported it recently, the file itself might be messed up. Try running flutter create test_project in Terminal to make a fresh Flutter project—check the lib/main.dart in this new project; if it looks normal, your original project's file might be corrupted. You can also run file lib/main.dart in Terminal: a valid Dart file will show something like ASCII text or UTF-8 text, while a dmg file will show disk image-related wording. If it's the latter, you'll need to get a fresh copy of the main.dart file.

  • Reset Finder's file association cache (if all else fails)
    Sometimes the system's cache gets stuck. Open Terminal and run killall Finder to restart Finder immediately. If that doesn't fix it, run this command to reset the entire system's file association cache:

    /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
    

    Then run killall Finder again, and your file icons should behave normally.

内容的提问来源于stack exchange,提问作者Charlie Pico

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 09:16:56