list method
Begins stream of statement
Items are being delivered as fast as possible if specified range is bigger than the one allowed by API
In such case statement is being requested by parts
Implementation
Stream<StatementItem> list({
/// Doesn't stop the stream if an error happens
///
/// Some items can be skipped without any warnings
bool ignoreErrors = false,
/// Reverse stream
///
/// `false`: from older to newer
/// `true`: from newer to older
bool reverse = false,
}) async* {
var lFrom = from, lTo = to;
while (reverse ? lTo.isAfter(from) : lFrom.isBefore(to)) {
if (reverse) {
lFrom = lTo.subtract(_maxRange);
if (lFrom.isBefore(from)) lFrom = from;
} else {
lTo = lFrom.add(_maxRange);
if (lTo.isAfter(to)) lTo = to;
}
final f = (lFrom.millisecondsSinceEpoch / 1000).floor();
final t = (lTo.millisecondsSinceEpoch / 1000).floor();
APIResponse data;
List<Map<String, dynamic>> body;
try {
data = await account.client.controller.call(APIRequest(
'personal/statement/${account.id}/$f/$t',
methodId: 'personal/statement',
useAuth: true,
));
body = List<Map<String, dynamic>>.from(data.body as Iterable<dynamic>);
} catch (e) {
if (!ignoreErrors) rethrow;
body = [];
}
final i = (reverse ? body : body.reversed)
.map((e) => StatementItem._fromJson(e, account));
for (final e in i) {
yield e;
}
if (reverse) {
lTo = lFrom.subtract(Duration(seconds: 1));
} else {
lFrom = lTo.add(Duration(seconds: 1));
}
}
}