Ad
I Have Migrated To Null-safety (2.15.1) And This Problem Still Persists
I get the error below when I compile the app.
The following NoSuchMethodError was thrown building MyApp(dirty, state: _MyAppState#73713):
The method 'call' was called on null.
Receiver: null
Tried calling: call(Instance of 'ChangeNotifierProvider<UserLoggedIn>')
The error points me to the 'MyApp' part of the code and so I have no idea how to tackle this one. My app ran with no error before migrating. This is a part of my code where the cause for this error is. I went through the code with and I can't find a possible syntax error.
void main() {
runApp(ProviderScope(child: MyApp()));
}
class MyApp extends StatefulHookWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _amplifyConfigured = false;
bool checkAuthStatus = false;
late AmplifyAuthCognito auth;
var userLoggedIn;
var useProvider;
@override
void initState() {
// TODO: implement initState
super.initState();
_configureAmplify();
}
void _configureAmplify() async {
if (!mounted) return;
auth = AmplifyAuthCognito();
await Amplify.addPlugin(auth);
try {
await Amplify.configure(amplifyconfig);
} on AmplifyAlreadyConfiguredException {
print('Already configured');
}
try {
getUserStatus();
setState(() {
_amplifyConfigured = true;
});
} catch (e) {
print(e);
}
}
@override
Widget build(BuildContext context) {
userLoggedIn = useProvider(userLoggedInProvider);
```
Ad
Answer
Riverpod removed useProvider
in version 1.0.0. As described in the migration guide, you will need to use StatefulHookConsumerWidget
instead of StatefulHookWidget
to access that same functionality in the newest version:
class MyApp extends StatefulHookConsumerWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends ConsumerState<MyApp> {
// ...
@override
Widget build(BuildContext context) {
userLoggedIn = ref.watch(userLoggedInProvider);
// ...
Ad
source: stackoverflow.com
Related Questions
- → How do you create a 12 or 24 mnemonics code for multiple cryptocurrencies (ETH, BTC and so on..)
- → Flutter: input text field don't work properly in a simple example..... where am I wrong?
- → Can I customize the code formatting of Dart code in Atom?
- → Is it possible to develop iOS apps with Flutter on a Linux virtual machine?
- → Display SnackBar in Flutter
- → JSON ObjectMapper in Flutter
- → Material flutter app source code
- → TabBarSelection No such method error
- → How do I set the animation color of a LinearProgressIndicator?
- → Add different routes/screens to Flutter app
- → Is there a way to get the size of an existing widget?
- → How to share a file using flutter
- → Is there an easy way to find particular text built from RichText in a Flutter test?
Ad