actually I want to convert a list of decimal to a list of hexadicimal. I tried .toRadixString(16) But I got : The method 'toRadixString' isn't defined for the type 'List'.. this is my code:
BehaviorSubject<List<int>> _value;
Stream<List<int>> get value => Rx.merge([
_value.stream,
_onValueChangedStream,
]);
List<int> get lastValue => _value.value ?? [];
Future<Null> write(List<int> value, {bool withoutResponse = false}) async {
final type = withoutResponse
? CharacteristicWriteType.withoutResponse
: CharacteristicWriteType.withResponse;
var request = protos.WriteCharacteristicRequest.create()
..remoteId = deviceId.toString()
..characteristicUuid = uuid.toString()
..serviceUuid = serviceUuid.toString()
..writeType =
protos.WriteCharacteristicRequest_WriteType.valueOf(type.index)!
..value = value.map((e) => e.toRadixString(16)).toList();
// Uint8List(4)..buffer.asInt32List()[0]=value;
//..value = value.toRadixString(16);
I would be very thankful if you can give me a solution for converting this list from decimal or int to hexadicimal.
[1]: https://i.stack.imgur.com/MVOkQ.png
CodePudding user response:
You are trying to use toRadixString on list.
as on https://api.flutter.dev/flutter/dart-core/int/toRadixString.html:
Converts this to a string representation in the given radix.
as in documentation you should use toRadixString on int.
in your case you can try this:
List get hexLastValue => _value.value.map((e) => e.toRadixString(16)).toList();
CodePudding user response:
The protos.WriteCharacteristicRequest.create()..value
requires List<int>
so you cant able to convert the hexa decimal string to int data type required by the protos.WriteCharacteristicRequest