Reputation: 33
I am having trouble with Android Studio immediately deleting my Dart/Flutter imports, especially if I click outside of Android Studio.
For example, I pasted these from another file into an empty file to refactor my code:
import 'package:http/http.dart' as http;
import 'dart:convert';
Before I can use the imports, Android Studio automatically deletes them. I went into Preferences > General > Auto Import. For Dart it has the line "Update imports on paste: Ask". I tried changing this to the other options of Never or Always and that didn't work. I also tried to change the Java settings (Currently under Java, Optimize imports on the fly is unchecked for me).
I don't mind that unused imports are deleted. I just don't like it that I basically have to create the code that uses the imports before the import will stay put at the top of the file without Android Studio auto-deleting them.
P.S. My current version of Android Studio is 4.2.1.
Upvotes: 0
Views: 1149
Reputation: 486
Just Uncheck this checkbox File
-> Settings
-> Languages & Frameworks
-> Flutter
-> Editor
-> Organize imports on save
Upvotes: 1
Reputation: 31
Unticking 'Organize imports on save' in 'File | Settings | Languages & frameworks | Flutter | Editor | Format code on save' works for me.
Upvotes: 3
Reputation: 601
Try to uncheck Format code on save in: File | Settings | Languages & Frameworks | Flutter
Upvotes: 0