![](/img/trans.png)
[英]type 'String' is not a subtype of type 'int' of 'index' Flutter
[英]type _Uint8ArrayView' is not a subtype of type 'String' in Flutter
我从我的应用程序中的 SQLite 数据库中获取数据并将该数据显示为列表,但是当我获得该值并尝试操作数据时,我收到此错误
我收到这个错误。
type '_Uint8ArrayView' is not a subtype of type 'String'
我显示这方面的数据
FutureBuilder<List<QuestionModel>>(
future: DatabaseHelper.instance.getQuestionList(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
QuestionModel item = snapshot.data[index];
return ListTile(
title: Text(item.questionen),
leading: Text(item.id.toString()),
);
},
);
}
else if(snapshot.hasError){
print('Error-------> ${snapshot.error}');
return Text('Error: ${snapshot.error}');
}
else {
return Center(child: CircularProgressIndicator());
}
},
)
这是我的 model class
class QuestionModel {
int id;
String questionen;
String opta;
String optb;
String optc;
int answer;
String imgpath;
QuestionModel(
{this.id,
this.questionen,
this.opta,
this.optb,
this.optc,
this.answer,
this.imgpath});
factory QuestionModel.fromMap(Map<String, dynamic> json) => new QuestionModel(
id: json["id"] ?? "",
questionen: json["questionen"] ?? "",
opta: json["opta"] ?? "",
optb: json["optb"] ?? "",
optc: json["optc"] ?? "",
answer: json["answer"] ?? "",
imgpath: json["imgpath"] ?? "",
);
}
这是从数据库中获取数据的 function
Future<List<QuestionModel>> getQuestionList() async {
final db = await database;
var res = await db.query("question_data");
print(res.toString());
List<QuestionModel> queList =
res.isNotEmpty ? res.map((c) => QuestionModel.fromMap(c)).toList() : [];
return queList;
}
我正在处理类似的问题,但试图从 postgres 获取 GIS 地理类型。
在你的情况下,如果你真的确定它是一个字符串,你可以使用 utf8.decode(uint8List)。 在构造函数中,请参见示例:
IoTDevice(index, mac, imei, backend, ByteData lastpos, status, lockstatus,
powerstatus, id, chargestatus, Uint8List lastping){
this.index = index;
this.mac = '';
for (final byte in mac){
this.mac += byte.toRadixString(16);
/// In your case, you should use: this.mac = utf8.decode(mac)
}
print('mac ${this.mac}');
this.imei = imei;
this.backend = backend;
if(lastpos != null){
var longitude = lastpos.getFloat64(0);//Still errors here, trying to solve
var latitude = lastpos.getFloat64(8); //Still errors here, trying to solve
print('Longitude: ${longitude}');
print('Latitude: ${latitude}');
this.lastpos = LatLng(longitude, latitude);
}
else {
this.lastpos = null;
}
print('lastpos ${this.lastpos}');
this.status = status;
this.lockstatus = lockstatus;
this.powerstatus = powerstatus;
this.id = id;
this.chargestatus = chargestatus;
lastping != null ? this.lastping = DateTime.tryParse(new String.fromCharCodes(lastping).trim()) : this.lastping = null;
print('lastping ${this.lastping}');
}
static IoTDevice fromDynamicMap(Map<String, dynamic> map) => IoTDevice(
map['index'],
map['mac'],
map['imei'],
map['backend'],
map['lastpos'],
map['status'],
map['lockstatus'],
map['powerstatus'],
map['id'],
map['chargestatus'],
map['lastping']
);
如果它不是字符串,它将启动偏移错误。
然后你必须用 ByteData go 并祈祷所有可用的神。 我现在就在这一点上,如果我得到任何启发,我会告诉你。
编辑:有关 Uint8Arrayviews 如何进入此处的其他信息 UInt8List 中的Unreadable Int16,cast asByteArray 时的错误数据
我希望在两条评论之间你可以修复它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.