Customization and Localization of Permissions in Flutter

Zaldy Pagaduan Jr.
5 min readMay 21, 2023
iOS & Android photo permissions

We will be discussing on how to achieve the following permissions in Flutter.

Android Customization

explain why your app needs permission

As of writing, Android does not allow custom message for their system permissions. Instead, they require you to explain why your app needs that permission, using your app’s UI element. After the user have read the app’s explanation and agreed, then call the Android permission.

Android Localization

android language settings

Localization is already handled by Android itself. Simply go to settings and change to the desired language. However, if you want to change the locale during runtime, this wouldn’t affect permissions locale since the permission depends on the Android system language.

android spanish permission

iOS Customization

photo library permission with custom content

Luckily iOS allows customization of permissions. On Xcode, go to Info.plist located in Runner > Runner. Select the privacy permission you want to update and change its value. In my case, I want to update the value of Photo Library Usage Description.

Info.plist location in Xcode

However we can only customize the content of the permissions. The headers and buttons value are controlled by iOS.

iOS Localization

Like Android, localization is already handled by iOS itself. Just change the language on the settings and the permission vocabulary would change.

spanish as the iOS language

However, if you have defined a custom content for the permission, then you have to create a new infoplist. This new infoplist would contain the custom content translated to the supported language, in this case spanish. Else you would end up with a permission like this: english content, but the headers and actions are in spanish.

partially localized permission

To create a translated custom content, first create a new file under Runner > Runner.

create new file

On the templates window, search for “string” under iOS.

search strings

and then save the Strings file as “InfoPlist.strings”

save as InfoPlist.strings

You should now have an empty InfoPlist.strings under Runner > Runner and should look similar to this.

newly added InfoPlist

We will now localize this newly created InfoPlist.strings, to do that first toggle the inspector by tapping on the upper right icon besides the + icon.

InfoPlist inspector on the right

On the inspector locate the “Localization” section and tap on the button “Localize…”

localized InfoPlist

The newly created InfoPlist should now look like this, having an InfoPlist (en) as its name.

We can now use this InfoPlist as the file containing all english permissions. To do that, we will declare them using the raw key as key and our custom content as the value. In our example the raw key of Photo Library Usage Description is “NSPhotoLibraryUsageDescription”, and we will supply it with our english content.

raw key and value declaration

If you want to get the raw key equivalent of the permissions, simply right click on Info and choose “Raw Keys and Values”

right click on Info to check the raw keys

Now we will update the localizations configuration of the main Runner. Under the main Runner, select Project > Runner and select the info section. Under info we have the localizations config.

runner > localization config

Below the last row we see a plus and minus text; we’ll choose the plus text and add our chosen language, in this example its Spanish (es).

tap on plus sign and choose language

Then a prompt would show asking where to reference this spanish language. Make sure to only check InfoPlist.strings and uncheck the first 2, Main.storyboard & LaunchScreen.storyboard

reference only InfoPlist.strings

Once done it should look like this, Localization would be updated with the new language Spanish, and to your left the InfoPlist will now have a dropdown icon, meaning a new strings file was created.

successfully added spanish in localizations

Tap on the InfoPlist dropdown and it will reveal the files under it, there should be 2 InfoPlists, one English and one Spanish. Open the InfoPlist (Spanish) and there we will update the spanish translation equivalent of our english content.

InfoPlist (Spanish) with update value

Run the app again and see that our custom content is now being localized.

localized custom permission

Changing Locale on runtime

Although we can change the locale of the app during runtime, this app locale can’t influence the locale of the system permissions of iOS or Android. For the permissions to change its language, the language settings of the Android or iOS phone should be set to the desired language.

--

--

Zaldy Pagaduan Jr.

susulatan ko lahat ng mga blangkong pahina maubusan man ng hininga