Created
November 29, 2023 14:29
-
-
Save mrocha98/ff652797b105f7f103357a75bbdab10c to your computer and use it in GitHub Desktop.
xablau mostRecentCompleted
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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