The parameter 'abc' can't have a value of 'null' because of its type, but the implicit default value is 'null' - flutter

#required to a property gave such ERROR:
The parameter 'lng' can't have a value of 'null' because of its type, but the implicit default value is 'null'. (Documentation)
but removing #, removes the error. how ?
I mean, the value still can be null. What does it have to do with "#" symbol.
see pictures:

You dont need to use # anymore, just use required.
({
required this.lat,
required this.lng,
})
if you like to accept null data, use DataType? varName.
String? lat;
String? lng;
More about understanding-null-safety

Related

flutter dart datetime in list<map> occur error

my code is below. I want it to be type-recognized as a datetime type at compile time.
var myList = [{
'message': 'foo',
'time': DateTime.now()
}];
DateTime.now().difference(myList[0]['time']);
and it has error of The argument type 'Object?' can't be assigned to the parameter type 'DateTime'.
how can i fix this?
You need to add a type cast for this with the as keyword:
DateTime.now().difference(myList[0]['time'] as DateTime)

Convert data Type into different data Type in dart

I am working in backend using dart. when i get a request i check the data type of all the values in key value pair. some times i receive data type.
_InternalLinkedHashMap<String, dynamic>
I need a where i can type cast a data-type
Type xyz = sumFunction(_InternalLinkedHashMap<String, dynamic>);
print(xyz);
output :
Map<String,dynamic>
Beacause when i am comparing
print(_InternalLinkedHashMap<String, dynamic> == Map<String,dynamic>);
output:
false
If anyone have any kind of solution please provide.

A value of type 'Employee?' can't be assigned to a variable of type 'Employee' because 'Employee?' is nullable and 'Employee' isn't

Error: A value of type 'Employee?' can't be assigned to a variable of
type 'Employee' because 'Employee?' is nullable and 'Employee' isn't.
.fromJson constructor your employee varable can be null as your initing it, but in model it declare like null safaty(by default). If your logic is requider this varible strongly, be shure is not null. Other way if it is not required you can use ? brfore class name, then it can be null!
Employee? employee;

Flutter: the operator '[]' isn't defined for the type 'Object'. Try defining the operator '[]'

How can I get the nested object values? print(_user.userLocation()['location']); returns {country: Eesti, city: Tallin}
So, I tried with _user.userLocation()['location']['city'] to get the value Tallinn. However, I am getting
The operator '[]' isn't defined for the type 'Object'. Try defining the operator '[]'.
print(_user.userLocation()) and print(_user.location().runtimeType); returns
location: {
country: Eesti,
city: Tallinn,
}
flutter: _InternalLinkedHashMap<String, dynamic>
I tried to set a variable to var a = _user.location()['location'] and then a['city']. However, this is not working as well.
You should try like this,
var a = _user.userLocation() as Map;
print(a['location]['city']);
I issue here is dart's type inference is not able to identify the type automatically.So that it gives the error.But the above solution should work

EntLib Way to Bind "Null" Value to Parameter

I wish to pass Null Value to the parameter as follow:
_db.AddInParameter(dbCommand, "Id", DBNull.Value, myContactPerson.Id);
I am receiving the following error :
"can not convert "System.DBNull to System.Data.DbType".
I know the meaning of this error.
But i need to supply null value to myContactPerson.Id
How can i achieve this ?
If myContactPerson.Id isn't an auto-number, then why not just pass 0.
DBType should be passed in that parameter and should match your the dbtype (string, int, etc.) for the table that you are comparing with in your database. You would replace your value field "myContactPerson.Id" with DBNull.Value to always pass the null value.