flutter - 将列表布尔值转换为列表字符串颤动
问题描述
如何将列表字符串转换为列表布尔值?
List<String> listString = ["true", "false, "true"]
List<bool> listBool = []
我试过这个
listBool = listString.map((f)=>(f.contains("true")? listBool.add(true): listBool.add(false)));
我的预期结果是
listBool = [true, false, true]
解决方案
您可以尝试使用 forEach 方法,如下所示:
List<String> listString = ["true", "false", "true"];
List<bool> listBool = <bool>[];
listString.forEach((item) => item == "true" ? listBool.add(true) : listBool.add(false));
推荐阅读
- python-3.x - 来自 Flask 中 FileStorage 的 Pandas read_csv
- ffmpeg - 如何更改参考帧值?
- python-3.x - 无法取消 Twisted Deferred 链 (AlreadyCalledError)
- html - Angular UI bootstrap tooptip 不是自动定位
- laravel - 在 Laravel 中,如果我需要会话参数,如何绑定模型实例?
- google-maps-api-3 - 如何在谷歌地图的标记内定位标签?
- javascript - 从 ExpressJS 应用程序在 axios 中设置动态标题
- xamarin - java.lang.OutOfMemoryError。考虑增加 $(JavaMaximumHeapSize) 的值
- r - 如何查找我们在特定列中是否有两个或多个相等的最小值
- .net - 从 Graphics 对象获取 uxtheme.dll DrawThemeParentBackground 的 hwnd