setTemplate method

  1. @override
Future<void> setTemplate(
  1. String filePath
)
override

setTemplate(String) takes a file path (i.e. 'assets/MyTemplate.BWT' or 'assets/MyImage.PNG') as a string representing a template file or image.

This method sets the current template or image being acted upon when setPlaceholderValue(String, String) or print() is called. Therefore, calling setTemplate(String) again will override any previous template that has been set.

Implementation

@override
Future<void> setTemplate(String filePath) async {
  String? fileExtension = filePath.split(".").lastOrNull;
  if (fileExtension != null) {
    final fileData = await rootBundle.load(filePath);
    final bytes = fileData.buffer.asUint8List();
    final byteData = base64.encode(bytes);
    var sendMap = <String, dynamic>{
      "byteData": byteData,
      "fileExtension": fileExtension
    };
    methodChannel.invokeMethod('setTemplate', sendMap);
  } else {
    debugPrint("INVALID FILE NAME. PLEASE INCLUDE FILE EXTENSION.");
  }
}