addPermission method

void addPermission({
  1. required String name,
  2. List<String>? comments,
  3. RemoveComment? removeCommentsOnUpdate,
  4. List<XmlElementInfo> extraTags = const [],
  5. int? maxSdkVersion,
})

Adds a permission to the manifest.

name The permission name (e.g., 'android.permission.CAMERA'). comments Optional comments to add above the permission. removeCommentsOnUpdate Predicate to determine which existing comments to remove. maxSdkVersion Optional max SDK version for the permission.

Implementation

void addPermission({
  required String name,
  List<String>? comments,
  RemoveComment? removeCommentsOnUpdate,
  List<XmlElementInfo> extraTags = const [],
  int? maxSdkVersion,
}) {
  // Remove existing permission if present
  removePermission(
    name: name,
    removeComments: removeCommentsOnUpdate,
  );

  insert(
    XmlInsertElementEdit(
      path: 'manifest',
      tags: [
        XmlElementInfo(
          name: 'uses-permission',
          comments: comments,
          attributes: {
            'android:name': name,
            if (maxSdkVersion != null)
              'android:maxSdkVersion': '$maxSdkVersion',
          },
          isSelfClosing: true,
        ),
      ],
      insertAfter: (tag, _) => tag == 'uses-permission',
    ),
  );
}