Created
September 5, 2020 06:31
-
-
Save ttlg/7fd8079aa998e24ba1cf7e2522c4c7fc to your computer and use it in GitHub Desktop.
sorted todos
This file contains hidden or 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
final sortedTodos = StateProvider<List<Todo>>((ProviderReference ref) { | |
final List<Todo> todos = ref.watch(_todos).state; | |
final SortOrder sortOrder = ref.watch(_sortOrder).state; | |
if (sortOrder == SortOrder.ASC) { | |
todos?.sort((a, b) => a.timestamp.compareTo(b.timestamp)); | |
} else { | |
todos?.sort((a, b) => b.timestamp.compareTo(a.timestamp)); | |
} | |
return todos; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pragmatic architecture using Riverpod