The argument type 'BuildContext?' can't be assigned to the parameter type 'BuildContext'. The method 'read' isn't defined for the type 'BuildContext' - flutter

I have tried many ways and still can't fix it
The argument type 'BuildContext?' can't be assigned to the parameter type 'BuildContext'. The method 'read' isn't defined for the type 'BuildContext'.

It is saying that, scaffoldState.currentContext can return null. you can do a null check and then use it like
if(scaffoldState.currentContext != null)ScaffoldMessenger.of(scaffoldState.currentContext)...
I dont prefer using ! directly.
I think you can use the parameter context.
ScaffoldMessenger.of(context)...

Related

Why getting The method 'contains' isn't defined for the type 'String'. flutter

I am using contains method for a string in dart but getting an error like this.
can anyone tell me what is wrong with using .contains for a string in dart
This is my code
String isPdf = "https://www.africau.edu/images/default/sample.pdf";
isPdf.contains("pdf");
Error occurs
The method 'contains' isn't defined for the type 'String'.
Try correcting the name to the name of an existing method, or defining a method named 'contains'.
In vscode quickfix tells me that
change the 'contains' method to 'oscontains'.

why is this error 'The argument type 'List<AddEventModel>' can't be assigned to the parameter type 'AddEventModel''?

This maybe a silly questain i'm a beginner so help me. It is showing argument type List and a model 'AddEventModel' i create for Hive can't be assigned to parameter type 'AddEventModel' it is a valueNotifier.
Simply you can use this for loop to add all events to the events notifier
for(var event in allEvents){
eventsNotifier.value.add(event);
}

The argument type 'JsObject' can't be assigned to the parameter type 'BuildContext'.dart

I am getting an error it is saying "The argument type 'JsObject' can't be assigned to the parameter type 'BuildContext'.dart"
error on this part Navigator.of(context).pop()
It looks like you've imported by mistake the dart:js module. If so, just remove it:
import 'dart:js'; // <- Remove this import
The dart:js module exports a global context of type JsObject and its type conflicts with the BuildContext type.

Null check operator used on a null value instagram clone

[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: type 'Null' is not a subtype of type 'Map<String, dynamic>' in type cast
This might have basically happened while parsing json data from server into dart object. The issue basically arises in general whenever the members of the dart class are not nullable in which case they can't be left null at the time of initialisation. Due to which while you use the fromJson factory or function the value assigned to this parameter doesn't have that key available in it as a consequence you receive this error.
This could also arise while using named pushing of routes via arguments.

argument type 'String?' can't be assigned to the parameter type 'String'

The argument type 'String?' can't be assigned to the parameter type 'String' i got this error but previously the code was working fine. i have seen people raising the same issue but am not understanding the root cause. the package am using is flutter_audio_query nullsafe version from github. can someone help me with the issue.
String? which is nullable and you cannot pass directly to the non-null fields.
So use like this,
await player.setUrl(songInfo.uri ?? ''); // if null then empty string will be passed.
or
await player.setUrl(songInfo.uri!); // this is you saying that it won't be null.