toJson method
Converts this Permission instance to a JSON-serializable Map
This method serializes the Permission object into a Map<String, dynamic> format that can be easily converted to JSON for storage, transmission, or communication with platform channels. This is particularly useful when passing permission data to native platform code or storing configuration in files.
Returns a Map containing:
- 'name': The display name of the permission (nullable String)
- 'description': The detailed description of why this permission is needed (nullable String)
- 'type': The permission type as a string representation (non-null String)
Example output:
{
"name": "Camera Access",
"description": "Allow the app to take photos and record videos",
"type": "camera"
}
Note: Null values for name and description will be preserved in the Map, allowing the receiving code to handle them appropriately.
Implementation
// ignore: unintended_html_in_doc_comment
/// This method serializes the Permission object into a Map<String, dynamic>
/// format that can be easily converted to JSON for storage, transmission,
/// or communication with platform channels. This is particularly useful
/// when passing permission data to native platform code or storing
/// configuration in files.
///
/// Returns a Map containing:
/// - 'name': The display name of the permission (nullable String)
/// - 'description': The detailed description of why this permission is needed (nullable String)
/// - 'type': The permission type as a string representation (non-null String)
///
/// Example output:
/// ```json
/// {
/// "name": "Camera Access",
/// "description": "Allow the app to take photos and record videos",
/// "type": "camera"
/// }
/// ```
///
/// Note: Null values for name and description will be preserved in the Map,
/// allowing the receiving code to handle them appropriately.
Map<String, dynamic> toJson() => {
'name': name,
'description': description,
'type': type.name,
};