A Flutter plugin integrated with Android-SerialPort-API.
This plugin works only for Android devices.
Future<List<Device>> findDevices() async {
return await FlutterSerialPort.listDevices();
}
Device theDevice = Device("deviceName", "/your/device/path");
int baudrate = 9600;
Serial serialPort = await FlutterSerialPort.createSerialPort(theDevice, baudrate);
bool openResult = await serialPort.open();
print(serialPort.isConnected) // true
bool closeResult = await serialPort.close();
print(serialPort.isConnected) // false
// Listen to `receiveStream`
serialPort.receiveStream.listen((recv) {
print("Receive: $recv");
});
serialPort.write(Uint8List.fromList("Write some data".codeUnits));
Check out the example.
If you bump into a issue like below.
Change the android:label
in AndroidManifest.xml
.
Check out this commit fix: 🐛 Fix Android build failed issue
This is all about Android permission problem. Please check out Issue #4.