3

Some one can help me. Error Message: A value of type 'String?' can't be assigned to a variable of type 'String'. Try changing the type of the variable, or casting the right-hand type to 'String'.

enter image description here

John Reaper
  • 269
  • 3
  • 15
  • Post your code. – Zakaria Hossain Mar 23 '22 at 08:41
  • Check my answer : https://stackoverflow.com/questions/71555669/flutter-router-the-argument-type-string-cant-be-assigned-to-the-parameter/71555872#71555872 – Yashraj Mar 23 '22 at 08:42
  • [Please do not upload images of code/errors when asking a question.](//meta.stackoverflow.com/q/285551) – tareq albeesh Mar 23 '22 at 08:50
  • Does this answer your question? [Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't](https://stackoverflow.com/questions/66798782/error-the-argument-type-string-cant-be-assigned-to-the-parameter-type-stri) – Ahmad F Mar 23 '22 at 08:51
  • https://dart.dev/guides/language/sound-problems – Furkan Mar 23 '22 at 09:12

4 Answers4

1

Dart supports sound null safety. Try using something like

String nonNullableString = nullableString ?? 'default';

OR

actions=uri.base.queryParameters["key"]!

Naveen Kulkarni
  • 633
  • 6
  • 16
1

Check some points with null safety declaration of data member of class. And also check out the type of action parameter what it takes- It may take String type of data then update your variables/data member accordingly.

Please look into the concept of null safety.

Vishal_VE
  • 1,852
  • 1
  • 6
  • 9
1

Use Null Safely code as this:

action = Uri.base.queryParameters['action']!; // add ! mark

The same process for all errors:

encryptedEmailAddress = Uri.base.queryParameters['encryptedEmailAddress']!; // add ! mark
doctorUID = Uri.base.queryParameters['doctorUID']!; // add ! mark
Mouaz M Shahmeh
  • 116
  • 2
  • 4
  • 18
1

As dart uses sound null safety, there are chances that the value in Uri.base.queryParameters["actions"] can be null. This is something that Flutter has adapted from the Swift programming language.

So basically, there are 2 ways you can solve this problem.

  1. Using the null check.
final String? actions = Uri.base.queryParameters["actions"];
if (actions == null) {
/// The value of [actions] is null
return;
}
/// Continue with your coding...
  1. By providing an optional value.
final String _actions = Uri.base.queryParameters["actions"] ?? "defaultValue";

I hope you understood what I am trying to say.

If you have any other doubts, do let me know.

Sagar Ghag
  • 105
  • 2
  • 4