I have a function that returns List But in my case I want to read and display float values. However, this function is a system function I can't update it.
My question is how to convert List to List?
This is the code:
characteristic.value.listen((event) async {
var bleData = SetupModeResponse(data: event);
});
Event is by default a List. When I try to declare data as List; I got List cannot assigned to List.
I would be very thankful if you can help me.
CodePudding user response:
you can use the map
method on list
like that:
List<int> intList = [1, 2, 3];
List<double> doubleList = intList.map((i) => i.toDouble()).toList();
You can learn more about dart list mapping here map method
CodePudding user response:
This should also work:
List<int> ints = [1,2,3];
List<double> doubles = List.from(ints);
CodePudding user response:
Yo can try this method and see if it works
List<int> num = [1,2,3];
List<double> doubles = List.from(num);
CodePudding user response:
Try the following code:
List<double> doubleList = event.map((i) => i.toDouble()).toList()