flutter - 从 Flutter 中的 Instance 获取价值
问题描述
我正在使用提供者模式在列表上发出搜索请求。
List<Device> _devices = [
Device(one: 'Apple', two: 'iphone'),
Device(one: 'Samsung', two: 'Galaxy')
];
查询是这样的
List<Device> queryQuery(String value) {
return _devices
.where((device) => device.one.toLowerCase().contains(value.toLowerCase()))
.toList();
当我传递值Apple时,我期望得到的结果是iphone。
但是当我这样编码时,我得到的屏幕上的结果是[instance of 'Device']
child: Text('${deviceData.getDevice('Apple')}'
我确实知道我应该使用某种键使用两个...但我不知道:-(
解决方案
您序列化了错误的对象。
你所做的最终类似于:
Text(Device(one: 'Apple', two: 'iphone').toString());
但你不想这样做Device.toString()
。相反,您想要的是传递Device.two
给您的Text
.
因此,您的最终结果是:
Text('${chordData.chordExpand('Apple').two}')
推荐阅读
- sql - SQL(网络)返回奇怪的行数
- django - Django Queryset 如何使用反向外键添加字段
- php - Laravel 规则错误使用 Laravel-build-form 包
- java - Wildfly 17 在同一服务器上启用 JMX 远程会导致 logmanager 错误
- android - Fiddler 不允许应用在 Android 上建立连接
- regex - 正则表达式不匹配整个字符串
- sockets - 是否有appengine数据存储命名空间和socket连接关系
- python - 使 Python 多处理池可等待
- python-3.x - OSX Catalina 中的 Samtools 问题,命令行找不到 Samtools 的图像
- pgadmin-4 - 为什么每个数据类型在 pgAdmin 4 中都有两种选择?