我想对一些包含数字的字符串进行排序,但经过排序后,它变成了这样["s1", "s10", "s11", ... ,"s2", "s21", "s22"]
。在我搜索后,我发现这个问题有同样的问题。但是在我的示例中,我有mutableList<myModel>
,并且我必须将所有字符串放入myModel.title
例如可变列表中并放入代码下:
val sortData = reversedData.sortedBy {
//pattern.matcher(it.title).matches()
Collections.sort(it.title, object : Comparator<String> {
override fun compare(o1: String, o2: String): Int {
return extractInt(o1) - extractInt(o2)
}
fun extractInt(s: String): Int {
val num = s.replace("\\D".toRegex(), "")
// return 0 if no digits found
return if (num.isEmpty()) 0 else Integer.parseInt(num)
}
})
}
Run Code Online (Sandbox Code Playgroud)
我在.sortedBy
和 中有错误Collections.sort(it.title)
,请帮我解决这个问题。
当我尝试用 id 更新表时,什么也不会发生。我没有收到任何错误,我不知道为什么会发生这种情况。首先,我尝试从字段中获取所有数据,然后如果所有字段都有值,则创建 User 对象并传递到更新表的方法中。我从上一屏幕中获取了 id,并从字段中获取了其他数据。当我检查时,我在 CompleteUserInformationScreen 的验证方法中拥有所有数据,并且我认为当我尝试使用 sqflite 调用更新方法时,某处发生了错误。
这是我更新表的方法:
Future<User> update(User user) async {
var dbClient = await db;
// return await dbClient.update(USER_TABLE, user.toMap(),
// where: '$NATIONAL_ID = ?', whereArgs: [user.nationalId]);
var res = await dbClient.rawQuery(
'UPDATE Customer SET $NAME = ${user.name}, $FAMILY = ${user.family}, $BIRTHDAY = ${user.birthday}, $MOBILE = ${user.mobile}, $NATIONAL_ID = ${user.nationalId} WHERE id = ${user.id}');
if (res.length > 0) {
return new User.fromMap(res.first);
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
这是我的屏幕:
import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:atlas_gen_demo/Animation/FadeAnimation.dart';
import …
Run Code Online (Sandbox Code Playgroud)