How to Change Package Name in Flutter?

In this guide, we’ll walk you through the steps to Change Package Name in Flutter using both Visual Studio Code and Android Studio.

 How to Change Package Name in Flutter?

Changing the package name in a Flutter project is a common requirement, especially when integrating with various services, like Firebase or Google Play Store. However, it’s crucial to execute this process correctly to avoid any complications.

Why Change Package Name in Flutter?

Before we dive into the steps, let’s quickly understand why changing the package name is necessary:

  1. Integration with Services: Many services, like Firebase, Google Play Store, or any third-party API, require a unique package name to identify your app correctly.
  2. Avoiding Conflicts: Changing the package name helps avoid conflicts with existing apps on the user’s device or on the app marketplace.
  3. Branding: Sometimes, apps undergo rebranding or need to be distinguished from other similar apps, making it essential to change the package name.

Using Visual Studio Code (VSCode) – Change Package Name in Flutter

Step 1: Rename the Package

  1. Open your Flutter project in VSCode.
  2. Navigate to the android/app/src/main/AndroidManifest.xml file.
  3. Inside this file, you’ll find the package attribute in the <manifest> tag. Change the value of this attribute to your desired package name.

Step 2: Update Gradle Files

  1. Navigate to android/app/build.gradle.
  2. Update the applicationId field under the defaultConfig block with your new package name.

Step 3: Refactor Dart Code

  1. Open the Dart file containing the main() function.
  2. Use VSCode’s built-in refactoring tool to rename the package. You can do this by right-clicking on the package name and selecting “Rename Symbol” or by pressing F2 on your keyboard.

Shortcut Command in VSCode – Change Package Name in Flutter

While there’s no built-in shortcut command for changing the package name in VSCode, you can utilize the refactoring tool (F2) to quickly rename symbols throughout your Dart codebase.

Using Android Studio

Step 1: Rename the Package

  1. Open your Flutter project in Android Studio.
  2. Navigate to android/app/src/main/AndroidManifest.xml.
  3. Change the package attribute in the <manifest> tag to your desired package name.

Step 2: Update Gradle Files

  1. Navigate to android/app/build.gradle.
  2. Update the applicationId field under the defaultConfig block with your new package name.

Step 3: Refactor Dart Code

  1. Right-click on the lib directory in Android Studio’s Project view.
  2. Select “Refactor” -> “Rename”.
  3. Enter your new package name and confirm the changes.

Shortcut Command in Android Studio:

Android Studio doesn’t have a specific shortcut command for changing the package name in Flutter projects. However, you can use the refactor option (Shift + F6) to rename the package throughout your Dart code or you can also use (ctrl + Shift + R)for search and replace.

Also Read:

Conclusion

Changing the package name in a Flutter project is a straightforward process but requires careful attention to avoid any errors.

By following the steps outlined above, you can seamlessly update your package name and ensure smooth integration with various services and platforms. Whether you prefer using Visual Studio Code or Android Studio, these steps will help you accomplish the task efficiently.

You can visit Flutter’s official documentation for more.

Share:
Ambika Dulal

Ambika Dulal is a Flutter Developer from Nepal who is passionate about building beautiful and user-friendly apps. She is always looking for new challenges and is eager to learn new things. She is also a strong believer in giving back to the community and is always willing to help others.

Leave a Comment

AO Logo

App Override is a leading mobile app development company based in Kathmandu, Nepal. Specializing in both Android and iOS app development, the company has established a strong reputation for delivering high-quality and innovative mobile solutions to clients across a range of industries.

Services

UI/UX Design

Custom App Development

Mobile Strategy Consulting

App Testing and Quality Assurance

App Maintenance and Support

App Marketing and Promotion

Contact

App Override

New Plaza, Kathmandu