ConsumerStatefulWidget constructor
const
ConsumerStatefulWidget({
- Key? key,
A StatefulWidget that has a State capable of reading providers.
This is used exactly like a StatefulWidget, but with a State that must subclass ConsumerState :
class MyConsumer extends ConsumerStatefulWidget {
const MyConsumer({Key? key}): super(key: key);
@override
ConsumerState<MyConsumer> createState() => _MyConsumerState();
}
class _MyConsumerState extends ConsumerState<MyConsumer> {
@override
void initState() {
// All State life-cycles can be used
super.initState();
}
@override
Widget build(BuildContext context) {
// "ref" is a property of ConsumerState and can be used to read providers
ref.watch(someProvider);
}
}
Implementation
const ConsumerStatefulWidget({super.key});