Why getting The method 'contains' isn't defined for the type 'String'. flutter - 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'.

Related

Target of URI doesn't exist: 'package:flutter/material.dart'

I've just set up my Windows 11 for Flutter development,
So I updated flutter SDK, and placed it in my Documents. After, I got this:
Target of URI doesn't exist: 'package:flutter/material.dart'.
The function 'runApp' isn't defined.
Classes can only extend other classes.
The name 'WidgetBuilder' isn't a type so it can't be used as a type argument.
Undefined class 'Widget'.
Undefined class 'BuildContext'.
The method 'MaterialApp' isn't defined for the type 'MyApp'.
The method 'ThemeData' isn't defined for the type 'MyApp'.
Undefined name 'Colors'.
The method doesn't override an inherited method.
What is an error? It's difficult to me.
Try running the following command in terminal:
flutter pub get

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

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)...

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.

DbProviderFactories.GetFactory Method (DbConnection) missing

According to MSDN there is an overload of GetFactory(DbConnection) in .NET 4. However, I can't invoke it - fails at compile time saying:
error BC30518: Overload resolution failed because no accessible 'GetFactory' can be called with these arguments:
'Public Shared Function GetFactory(providerRow As System.Data.DataRow) As System.Data.Common.DbProviderFactory': Value of type 'System.Data.Common.DbConnection' cannot be converted to 'System.Data.DataRow'.
'Public Shared Function GetFactory(providerInvariantName As String) As System.Data.Common.DbProviderFactory': Value of type 'System.Data.Common.DbConnection' cannot be converted to 'String'.
Is there something wrong with my .NET FW or is it a typo in documentation?
You can call the "GetFactory" method using the following solution:
https://msdn.microsoft.com/en-us/library/dd0w4a2z%28v=vs.110%29.aspx
DbProviderFactory factory =
DbProviderFactories.GetFactory(providerName);