Abhilash
Abhilash

Reputation: 2953

Android studio not recognising a file if a specific name is given

Using android-studio for flutter development. After creating a new flutter app I created another file named

home.dart

But android-studio is not recognizing the file. The page won't show autocomplete or anything. can see that <code>home.dart</code> don't have the globe symbol before the file name.

Also I can see that home.dart don't have the globe symbol before the file name(in left side like other files). If I put any other file name it works fine. Could someone find what's the issue?

Update

I think its some sort of bug. I even tried creating a fresh project and tried the same. If I put another name it works fine(I tried hom.dart and it works). But if I rename it as home.dart it is having this weird error.

Thank you

Upvotes: 8

Views: 2856

Answers (4)

matteoh
matteoh

Reputation: 3620

I managed to make it work by doing the following (on Android Studio for MacOS):

  • on the not recognized Dart file, right click and click on Override File Type
  • in the list that appears, select: Dart

Upvotes: 4

Ahmed Hamdy
Ahmed Hamdy

Reputation: 11

I faced this issue yesterday, I found no reason but when I changed the file name the problem fixed.

Upvotes: 0

Ovidiu
Ovidiu

Reputation: 8714

You have associated a different file type to that specific file by creating it as a regular file (right click -> New -> File) which has no implied type and instead shows a list of types to select from. You may have just clicked Next without changing the default selection of file type of 'Text'. Renaming the file afterwards may or may not change its type depending on the version of Android Studio.

In order to fix it, open settings (Ctrl + Alt + S), go to Editor -> File Types, scroll down and select 'Text' from the list of file types, select your file from the list at the bottom, and click the minus (-) sign to remove it. Your file should no longer be associated to a type of 'Text' - I'm not sure whether it will automatically be reassigned based on its extension or not, but you should now be able to delete it and create it again with the same name without automatically setting itself back to 'Text'

Upvotes: 28

Lady_A
Lady_A

Reputation: 27

have you tried building the project?

The file wont show autocomplete or anything because it is been treated as a normal text file. When adding additional dart files you can right click on your lib folder and add a new Dart File.

enter image description here

Upvotes: 0

Related Questions