I am using InheritedWidgets for the first time and I think it has been implemented correctly apart from one place. A ShowDialog that is getting called upon pressing of FAB. The of method of the InheritedWidget fails and the assert method returns null.
Code is below where it is called.
class ParameterDialog extends StatefulWidget {
const ParameterDialog({super.key});
@override
State<ParameterDialog> createState() => _ParameterDialogState();
}
class _ParameterDialogState extends State<ParameterDialog> {
@override
Widget build(BuildContext context) {
final inheritedProvider = HomePageInheritedWidget.of(context);
return FloatingActionButton(
key: const ValueKey('HomePageFloatingActionButton'),
onPressed: () {
setState(() {
inheritedProvider.objects.textFieldEnabled = false;
inheritedProvider.objects.textEditingController.clear();
});
showDialog(
context: context,
builder: (BuildContext context) {
final inheritedProvider=HomePageInheritedWidget.of(context);//this of method calling is returning null and the application halts.
return StreamBuilder(
stream: inheritedProvider.objects.counterBloc.counter,
initialData: 2,
builder: (
BuildContext counterContext,
AsyncSnapshot<int> counterSnapshot,
) {
return Center(
child: Card(
key: const ValueKey('CardForParameters'),
elevation: 20,
shadowColor: Colors.yellow,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
WidgetFailingIW(
counterSnapshot: counterSnapshot,),