writeDataFile method
This writes the file containing the messages, which can be either a binary
.carb
file or a JSON file, depending on the serializer.
This message data file must be shipped with the application, it is unpacked at runtime so that the messages can be read from it.
Returns the list of indices of the messages which are visible to the user.
Implementation
Future<void> writeDataFile(MessagesWithMetadata messages) async {
final serialization = serializer.serialize(
messages.hash,
messages.locale,
messages.messages.map((e) => e.message).toList(),
);
final carbFile = messages.assetId.changeExtension('.json');
final data = serialization.data;
if (data is Uint8List) {
await buildStep.writeAsBytes(carbFile, data);
} else if (data is String) {
await buildStep.writeAsString(carbFile, data);
}
}