Skip to content

Instantly share code, notes, and snippets.

@mrocha98
Created November 29, 2023 14:29
Show Gist options
  • Save mrocha98/ff652797b105f7f103357a75bbdab10c to your computer and use it in GitHub Desktop.
Save mrocha98/ff652797b105f7f103357a75bbdab10c to your computer and use it in GitHub Desktop.
xablau mostRecentCompleted
class Xablau {
const Xablau(this.id, [this.completedAt]);
final int id;
final DateTime? completedAt;
@override
String toString() => 'Xablau($id, $completedAt)';
}
void main() {
final data = <Xablau>[
const Xablau(1),
Xablau(2, DateTime(2022, 12, 25)),
const Xablau(3),
Xablau(4, DateTime(1999, 2, 28)),
Xablau(5, DateTime(2001, 11, 9)),
const Xablau(6),
];
if (data.isEmpty) {
//return; // sem context.push(/tralala)
}
//final mostRecentCompleted = data.fold<Xablau?>(null, (mostRecent, current) {
// if (mostRecent == null || mostRecent.completedAt == null) return current;
// if (current.completedAt == null) return mostRecent;
// if (current.completedAt!.isAfter(mostRecent.completedAt!)) return current;
// return mostRecent;
//});
final mostRecentCompleted =
data.where((xablau) => xablau.completedAt != null).fold<Xablau?>(
null,
(mostRecent, current) {
if (mostRecent == null) return current;
if (current.completedAt!.isAfter(mostRecent.completedAt!)) return current;
return mostRecent;
},
);
// if (StackView.maybeOf(context) != null) {
// stackViewCubit.hideList();
// }
if (mostRecentCompleted != null) {
// context.push(/tralala, mostRecent.id)
} else {
// context.push(/tralala, data.first.id)
}
print(mostRecentCompleted);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment