late initialize a field with ref.watch #2977
Answered
by
rrousselGit
AlwinFassbender
asked this question in
Q&A
-
|
Hi everyone, assuming I have a stateful widget like this class ExampleWidget extends ConsumerStatefulWidget {
const ExampleWidget();
@override
ConsumerState<ExampleWidget> createState() => ExampleWidgetState();
}Now it would be possible to initialize a field in this way. class ExampleWidgetState extends ConsumerState<ExampleWidget> {
late final _provider = ref.watch(exampleProvider);
@override
Widget build(BuildContext context) {
// assume _provider is used here
return const Placeholder();
}
}Is this okay, or do i have to declare a |
Beta Was this translation helpful? Give feedback.
Answered by
rrousselGit
Oct 12, 2023
Replies: 1 comment 2 replies
-
|
Watch your provider in the build method. You shouldn't use it like this. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
AlwinFassbender
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Watch your provider in the build method. You shouldn't use it like this.