Skip to content

Instantly share code, notes, and snippets.

@ttlg
Created September 5, 2020 06:31
Show Gist options
  • Save ttlg/7fd8079aa998e24ba1cf7e2522c4c7fc to your computer and use it in GitHub Desktop.
Save ttlg/7fd8079aa998e24ba1cf7e2522c4c7fc to your computer and use it in GitHub Desktop.
sorted todos
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;
});
@ttlg
Copy link
Author

ttlg commented Sep 5, 2020

Pragmatic architecture using Riverpod

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment