I understand this is more of a question than it is an issue, but I don't know where else to ask.
I am using provider version 4.0.2 and I get this error i the console: "The getter 'owner' was called on null."
I do not know how to resolve this issue. Any help is appreciated! Thank you in advance!
It sounds like you used a context that was null
I've looked into it, but it seems ok to me.
I will post a sample of my code so maybe you could have a better understanding of what's going on.
Sorry for not knowing how to parse the code nicely here. :/
Here's my code:
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:after_layout/after_layout.dart';
class ActivityTab extends StatefulWidget {
@override
_ActivityTabState createState() => _ActivityTabState();
}
class _ActivityTabState extends State
@override
void initState() {
super.initState();
Future.delayed(Duration.zero, () {
_loadData();
});
}
@override
void afterFirstLayout(BuildContext context) {
_markAllAsUnread(context);
}
void dispose() {
super.dispose();
}
}
@override
Widget build(BuildContext context) {
/// my layout
}
_markAllAsUnread(BuildContext context) {
// the line underneath is giving me the error
final auth = Provider.of
auth.clearActivity();
}
@usherwalce you are missing type. Provider.of
I was encountering this error in my Change Notifier Listener:
My solution:
if (this.mounted) {
//Do Something e.g
//Provider.of<MyDataModel>(context)
//Provider.of<MyDataModel>(context, listen: false)
}
check if context != null
Most helpful comment
It sounds like you used a
contextthat wasnull