Adding custom metadata to feedback
Wiredash automatically collects basic metadata about the device, such as screen size and Flutter version. However, there are situations where adding custom metadata can provide additional context to feedback, enhancing its value.
Providing custom metadata
To include custom metadata with your feedback, implement the collectMetaData
callback. This callback will be triggered during the feedback process, allowing you to supply the necessary information. It may be called multiple times, particularly when the user attaches more than one screenshot, enabling you to capture dynamic data like the current route.
return Wiredash(
// ...
collectMetaData: (metaData) => metaData
// Custom metadata
..custom['customKey'] = 'customValue'
..custom['nested'] = {
'emails_read_today': 13,
'items': [5, 7, 8, 9],
'doubleValue': 1.0,
'intValue': 1,
'stringValue': 'string',
'boolValue': true,
'lastLogin': _lastLogin.toIso8601String(),
},
);
INFO
All data types added to metadata must be serializable. For instance, DateTime
is not directly serializable—use dateTime.toIso8601String()
instead. If Wiredash cannot serialize custom metadata using jsonEncode
, it will be excluded before being sent to the Wiredash Console, and an error message will be logged in the console. Be sure to monitor the console during development.
The metaData
object is mutable by design. It retains the values set during the last collectMetaData
invocation and any properties set via Wiredash.of(context).setUserProperties()
or Wiredash.of(context).modifyMetaData()
.
Setting metadata directly
If you prefer not to use the callback or require precise control over when custom metadata is added, you can set custom properties directly using Wiredash.of(context).setUserProperties()
or Wiredash.of(context).modifyMetaData()
.
For detailed guidance on manipulating metadata and setting build properties, refer to the Metadata Reference.
Clearing Collected Metadata
In some cases, such as when a user logs out, you may need to reset or completely clear metadata.
To remove all metadata, simply call Wiredash.of(context).resetMetaData();
.
If you need to remove specific metadata fields, set their values to null
:
Wiredash.of(context).modifyMetaData((metadata) => metadata
..userEmail = null
..userId = null
..custom.remove('subscription'),
);
INFO
You are responsible for the accuracy and appropriateness of the properties sent to the console. Ensure that you have obtained the necessary user consent before adding any information to the custom metadata.