Sometimes you might want to create a new app using a pre-existing codebase. When the app connects to a Firebase database, this is a little bit complicated. If you simply copy the old code, you will be referencing the old app name in various places, which creates strange behavior.
Here are the steps that I’ve found necessary when trying to create a new app based off of a pre-existing app:
Bring up the repo you wish to use a template in a browser, click on the “Code” button, and download a copy of the files from the main branch as a zip file.
Create your new repository in GitHub, and clone it to your local computer.
Use the flutter create <appname> --overwrite
command to create a new Flutter app skeleton in your new repo. Crucially, this skeleton will contain subdirectories referencing your new app name.
Copy the pubspec.yaml file from the expanded .zip file. Edit the name field to your new app name.
Create the Firestore database. You can follow the Firestore Setup Cheat Sheet.
Initialize the Firestore database with sample data if desired. For further information, see these instructions for uploading data to Firestore with Firefoo.
Copy the lib/
and assets/
directories and the analysis_options.yaml
file from the expanded .zip file into your new repo. Check for any compiler errors with this code and fix if necessary. Run Dart Analysis and fix any errors.
Run flutterfire configure
. See FlutterFire CLI instructions for details on how to run this command.
You should now be able to run the code in the simulator. You’ll need to re-register any users since you’re using a fresh database, but if you uploaded sample data, it should appear.