FengChendian / serial_port_win32

A flutter SerialPort library using win32 API.
BSD 3-Clause "New" or "Revised" License
30 stars 8 forks source link

onDone or OnErr #2

Closed hamidjalili59 closed 3 years ago

hamidjalili59 commented 3 years ago

Salute bro 🙋 Can you put an function to execute codes before disconnecting the port Like onDone() or onErr() 🙏 These two are very useful in the serial port Thanks 🥰

FengChendian commented 3 years ago

emm... Do you mean port.close().onError((error){}).onDone((){}) which like stream?

I can try it, but I'm not very familiar with Stream or implementing Stream like function. Maybe it will take some time.

FengChendian commented 3 years ago

done

port.closeOnListen(
  onListen: () => print(port.isOpened),
)
  ..onError((err) {
    print(err);
  })
  ..onDone(() {
    print("is closed");
    print(port.isOpened);
  });

I did't test onError because I think it can work.