Created
July 2, 2020 04:26
-
-
Save rrousselGit/ddd92ae211bee94b0188ddec4e01e2cd to your computer and use it in GitHub Desktop.
reading a family without the key
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
final todosFamily = ProviderFamily<Todo, int>((ref, id) { | |
return Todo( | |
id: '$id', | |
description: 'Todo $id', | |
); | |
}); | |
final currentTodo = Provider<Todo>((ref) => null); | |
class List extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return ListView.builder( | |
itemBuilder: (context, index) { | |
return ProviderScope( | |
overrides: [ | |
currentTodo.overrideAs( | |
Provider((ref) => ref.read(todosFamily(index))), | |
), | |
], | |
child: Item(), | |
); | |
}, | |
); | |
} | |
} | |
class Item extends HookWidget { | |
@override | |
Widget build(BuildContext context) { | |
final todo = useProvider(currentTodo); | |
return Text(todo.description); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment