Skip to content

[Feature Request] Default alias for a file #4590

Open
@matanshukry

Description

@matanshukry

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

  1. Create a file and add a const variable in the global namespace, such as app_constants.dart with:
const app_name = 'MyApp';
  1. Mark the file app_constants.dart as having an alias of app_consts. This step can be done in project settings or by right clicking a file. Any way is fine to begin with.

  2. In another source file, use the app_name (without importing app_constants.dart file):

return Text(app_name);
  1. 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);

Activity

stevemessick

stevemessick commented on Jun 1, 2020

@stevemessick
Member

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?

modified the milestones: Backlog, On Deck on Jun 1, 2020
Tasen-pro

Tasen-pro commented on Sep 9, 2021

@Tasen-pro

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @matanshukry@helin24@stevemessick@Tasen-pro

        Issue actions

          [Feature Request] Default alias for a file · Issue #4590 · flutter/flutter-intellij