Flutter import 子文件夹下面的dart 文件时无法找到dart文件的解决方案
最近在写flutter 程序的时候,出现一个奇怪的问题,
import 'pages/tabs.dart';
明明子文件夹下面的dart文件存在,但是在main.dart导入时就是提示错误找不到,尝试修改项目的iml文件来添加子文件夹,居然解决了,奇怪了的问题。分享一下经验给大家。
projectname.iml 文件:
添加第七行的目录:
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lib/pags" isTestSource="false" /> //这一行存放dart文件的子文件夹
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>