问题
How do I write a byte array in Dart? I want to implement this function, but it is Java code with byte[]
in it. Can it be written in Dart as well?
public static byte[] encrypt(byte[] key, byte[] data) throws Exception {
try {
return performCipher(Cipher.ENCRYPT_MODE, key, data);
} catch (Exception e) {
throw new Exception(e);
}
}
回答1:
What you are looking for is Uint8List
. It is the equivalent of byte[]
of Java in Dart. Every single value has an equivalent in another language, so byte[]
in a few languages is like:
- Java:
byte[]
- Dart:
Uint8List
- iOS:
FlutterStandardTypedData -> typedDataWithBytes
I recommend looking at the documentation for more: https://flutter.dev/docs/development/platform-integration/platform-channels#codec
来源:https://stackoverflow.com/questions/57291240/how-can-i-write-byte-array-in-dart