fetchHistory method
page
is pagination index number
limit
is pagination limit number
value is must be 4, 8, 12, ...
Implementation
Future<List<History>> fetchHistory({
int page = 1,
int limit = 4,
List<String>? profiles,
}) async {
var historyPaths = paths(profileFile: historyFile, profiles: profiles);
List<History> histories = [];
for (var historyPath in historyPaths) {
var size = await File(historyPath).length();
if (size == 0) continue;
var dir = await Directory.systemTemp.createTemp();
var f = File('${dir.path}/$historyFile');
await f.create();
String tmpFile = f.path;
await copyFile(File(historyPath), tmpFile);
var conn =
sqlite3.open('file:$tmpFile?mode=ro&immutable=1&nolock=1', uri: true);
// int offset = page < 1 ? 0 : (page - 1) * limit;
var stmt = conn.prepare(historySQL);
var result = stmt.select([limit / 4, page < 1 ? 0 : page - 1]);
for (var e in result) {
histories.add(History.fromJson(e));
}
conn.dispose();
}
return histories;
}