Skip to main content

Put the email address for "Write to us" into .env

With email_feedback, the row "Write to us" of the settings screen, or a button of yours that calls appFeedback.open(context), opens a new mail in the mail app of the device. The mail goes to the address in EMAIL_FEEDBACK_ADDRESS of .env.

While that key is empty, or has a value that is not one email address, the app does not offer the way to write: appFeedback.available is false, the row "Write to us" hides from the settings screen, and a debug build prints which key to fill in.

.env is one file for all flavors, so every build sends its mails to the same address. The mail of a build of another flavor than prod names its flavor, so you can tell the mails of a test build apart. Nothing repeats for the other flavors.

1. Choose the address. The address goes into the app, where anyone can read it, so use an address for support with a filter of spam rather than your own, such as support@example.com. It is one address: a name, an @ and a domain with a dot, with no space. Two addresses, or an address with a query, count as none.

2. Put it into .env. In .env at the root of the app:

.env
EMAIL_FEEDBACK_ADDRESS=support@example.com

.env stays out of git. On another machine, copy .env.example to .env and fill it in again.

3. Start the app again. The flutter tool reads .env when a command starts, so stop flutter run and start it again with the values:

flutter run --dart-define-from-file=.env

Run and Debug of VS Code, and the run configuration of the app in Android Studio, pass the argument for you.

Check. A debug build no longer prints that EMAIL_FEEDBACK_ADDRESS is empty or no email address, and in an app with a settings screen the row Write to us shows there. Run the app on an iPhone, or on an Android device or emulator with a mail app and an account in it, such as Gmail, and tap the row: a new mail to your address opens, with the subject "Feedback: " and the name of the app, and the lines of the app and of the device below the room for the message. Where no mail app opens it, such as on the iOS simulator, which has no Mail, a sheet shows the address with a button that copies it.