Skip to content

Instantly share code, notes, and snippets.

@Norbert515
Created August 26, 2022 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Norbert515/7c267f9a4f19fcda7f656266dc5784b7 to your computer and use it in GitHub Desktop.
Save Norbert515/7c267f9a4f19fcda7f656266dc5784b7 to your computer and use it in GitHub Desktop.
/*
Problem statement:
Coming up with an easy to use and understand architecture, where the naming of 'things' makes inherent sense.
My basic architecture:
top_level:
- utils
- widgets
- other_very_important_top_level_stuff
- modules
- profile
- profile_page.dart
- data
- profile_repository.dart
- other_classes_that_are_directory_data_retrival_related.dart
- model
- profile.dart
- riverpod <-- would like to come up with a nice name for this
- riverpod.dart <-- contains providers for this module, can be consumed in widgets or other modules
- usecase <-- would like another name, contains functions that represent a small business rule
- update_profile_usecase.dart
I would rather not have the logic in a state notifier because it misses the point of state notifier. I don't need any state coming out
of the state notifier as most of my state is purely driven by data and riverpod transformations.
Also grouping 'units of work' the same way riverpod does with data transformation would make a lot of sense in the context.
*/
// A 'unit of work', 'usecase' or just a function would include stuff like
// This is just an example
Future<void> createGroup(String name, List<String> userIds) async {
var groupId = await ref.read(groupRepositoryProvider).createGroup(name);
for(var id in userIds) {
var user = await ref.read(userRepositoryProvider).getUser(id);
if(user.canBeInvitedToGroups) {
await ref.read(userRepositoryProvider).addUserToGroup(id, groupId);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment