how to filter null values from map in Dart

前端 未结 4 1678
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 09:49

Following the map, having both key-value pair as dynamic, Write a logic to filter all the null values from Map without us?

Is there any other approach than traversin

4条回答
  •  一向
    一向 (楼主)
    2021-01-13 10:45

    You can now use a map literal with conditional entries:

    Map toMap() => {
      if (firstName != null) 'firstName': firstName,
      if (lastName != null) 'lastName': lastName,
    };
    
    

提交回复
热议问题