skip to Main Content

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.

4

Answers


  1. 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

    Login or Signup to reply.
  2. This should also work:

    List<int> ints = [1,2,3];
    List<double> doubles = List.from(ints);
    
    Login or Signup to reply.
  3. Yo can try this method and see if it works

    List<int> num = [1,2,3];
    List<double> doubles = List.from(num);
    
    Login or Signup to reply.
  4. Try the following code:

    List<double> doubleList = event.map((i) => i.toDouble()).toList()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search