ToastService constructor

ToastService({
  1. required String appName,
  2. required String companyName,
  3. required String productName,
  4. String? subProductName,
  5. String? versionInformation,
})

Implementation

ToastService({
  required this.appName,
  required this.companyName,
  required this.productName,
  this.subProductName,
  this.versionInformation,
  }) {
  List<String> executableDirectory = Platform.resolvedExecutable.split('/')..removeLast();
  CallbackFFI.initialize(
    DynamicLibrary.open(path.joinAll(executableDirectory + ['desktoasts.dll']))
  );
  ToastServiceFFI.create(
    [
      this.appName,
      this.companyName,
      this.productName,
      this.subProductName ?? '',
      this.versionInformation ?? '',
    ].toNativeUtf16Array()
  );
  this._streamController = new StreamController<ToastEvent>.broadcast();
  this.stream = this._streamController.stream;
  receiver.listen((dynamic message) {
    List<String> response = (message as List<dynamic>).cast<String>();
    switch (response[0]) {
      case 'activateEvent': {
        _streamController.add(new ToastActivated());
        break;
      }
      case 'interactEvent': {
        _streamController.add(new ToastInteracted(
          action: int.tryParse(response[1]),
        ));
        break;
      }
      case 'dismissEvent': {
        _streamController.add(new ToastDismissed());
        break;
      }
      default: break;
    }
  });
}