Open
Description
Suggestion
Dart suppose the idea of global scope, and in certain flies it is common to use an alias when importing them. For example:
import 'package:path/path.dart' as path;
import 'package:http/http.dart' as http;
When you try to use an object (variable/method/etc) from a flie that exist in the global namespace, intellij will suggest importing the specific file, but will import it without the alias.
It would be nice if one could mark a specific file as an alias, so when IntelliJ would import the file it would automatically use the alias
How would it look once the feature is implemented
- Create a file and add a const variable in the global namespace, such as
app_constants.dart
with:
const app_name = 'MyApp';
-
Mark the file
app_constants.dart
as having an alias ofapp_consts
. This step can be done in project settings or by right clicking a file. Any way is fine to begin with. -
In another source file, use the app_name (without importing
app_constants.dart
file):
return Text(app_name);
- IntelliJ will now suggest you auto-import
app_name
. If you've chosen, the result file will look like this:
import 'package:myapp/app_constants.dart' as app_consts;
return Text(app_consts.app_name);
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
stevemessick commentedon Jun 1, 2020
Interesting, thanks for the suggestion!
It would be nice if whatever solution we use could work for both IntelliJ and VS Code. I wonder if the Flutter team would object to us adding stuff to the
.metadata
file? We need somewhere to store the aliases, and it should be managed by VCS. @cbracken do you know who to contact regarding.metadata
?Tasen-pro commentedon Sep 9, 2021
+1