Is there a way to change the name in the pubspec yaml file and automatically update all file import statements? (Flutter)

huangapple go评论68阅读模式
英文:

Is there a way to change the name in the pubspec yaml file and automatically update all file import statements? (Flutter)

问题

以下是要翻译的内容:

使用Flutter和Android Studio时的一个小格式问题:
我想要更改pubspec.yaml文件中的名称(自从开始以来,我已经更改了我的应用程序的名称)。
这个小问题(但非常耗时)是,如果我更改名称,那么我需要更新我的所有文件中的导入语句,这将变成一个相当大的任务(我后悔没有使用相对导入语句)。
所以我想知道是否有更简单的方法来做到这一点?

英文:

A small formatting question using Flutter with Android Studio:

I want to change the name in my pubspec.yaml file (I have changed my app's name since starting).

The minor (but very time intensive) issue is if I change the name I then need to update all my import statements in my files which turns into quite a large task (I regret not using relative import statements).

So I am wondering if there an easier way to do this?

Is there a way to change the name in the pubspec yaml file and automatically update all file import statements? (Flutter)

答案1

得分: 1

  1. 在你的pubspec.yaml文件中更改应用程序名称:

  2. 按下Ctrl + Shift + R(Windows/Linux)或Cmd + Shift + R(Mac)以打开“在路径中查找和替换”对话框。

  3. 在“查找”字段中输入旧的应用程序名称(例如,import 'package:old_app_name)。

  4. 在“替换为”字段中输入新的应用程序名称(例如,import 'package:new_app_name)。

  5. 确保“文件掩码”字段设置为*.dart,以仅在Dart文件中搜索。

  6. 选择“目录”范围并确保选择了项目的根目录。

  7. 单击“查找”按钮以显示搜索结果。

  8. 检查更改,如果一切看起来正常,请单击“全部替换”。

英文:

I use Find and Replace

  1. Change the app name in your pubspec.yaml file:

  2. Press Ctrl + Shift + R (Windows/Linux) or Cmd + Shift + R (Mac) to open the "Find and Replace in Path" dialog.

  3. In the "Find" field, enter the old app name (e.g., import 'package:old_app_name).

  4. In the "Replace with" field, enter the new app name (e.g., import 'package:new_app_name).

  5. Make sure the "File mask" field is set to *.dart to search only in Dart files.

  6. Choose the "Directory" scope and ensure that the root directory of your project is selected.

  7. Click on the "Find" button to show the search results.

  8. Review the changes, and if everything looks good, click on the Replace All.

huangapple
  • 本文由 发表于 2023年5月21日 19:46:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76299755.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定