L
L
Leopandro2021-06-23 11:18:48
Dart
Leopandro, 2021-06-23 11:18:48

How to fix type mismatch in dart?

An error like this is thrown

A value of type 'Object?' can't be assigned to a variable of type 'Object'.

How to make an Object from an Object?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mikeyuri, 2021-06-23
@mikeyuri

// nullable может быть String или null
final String? nullable = "value";
  
// Если в nullable будет null - присвоит 
// переменной nonNullable1 значение "default"
final String nonNullable1 = nullable ?? "default";
  
// Вызовет ошибку времени выполнения, 
// если в nullable будет null
final String nonNullable2 = nullable!;

null safety

N
Neonoviiwolf, 2021-06-23
@Neonoviiwolf

do you have null safety, Object? implies the possibility of null, Object - no

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question