Questions tagged [dart-null-safety]

Tag for questions regarding Dart code involving non-nullable types. This should only be used in combination with the Dart tag.

With the announcement of null safety, there are two types of Dart code:

  • Code with only nullable types.
  • Code with null safety enabled → with non-nullable types.

The tag covers questions involving the latter. Question with this tag should be subset of .

1185 questions
2
votes
1 answer

What does "!" this operator means in dart when it using like below?

final user = FirebaseAuth.instance.currentUser; print(user); if (user!.emailVerified) { print('User is veryfied'); } else { print('please verify'); …
Nirosh
  • 63
  • 8
2
votes
1 answer

Nullable evaluation of function with non-null arguments

S? _nullableEvaluation(S Function(T) f, T? nullableArgument) => nullableArgument == null ? null : f(nullableArgument); Is there something in the dart language like the above, some built-in language feature? Not that it's hard to write…
jakobleck
  • 43
  • 8
2
votes
1 answer

Error related to The argument type 'Object' can't be assigned to the parameter type 'ImageProvider?'
I'm having a problem with null safety and I don't know how to solve it please help. var profileImage = SocialCubit.get(context).profileImage; CircleAvatar( backgroundImage: profileImage == null ? NetworkImage('${userModel.image}') :…
2
votes
2 answers

Dart check nullable Type

I looking to find a way to check if the type is nullable using switch statement but I got an error by doing that. Doesn't anyone know how to check if the type of object in the nullable state? void dataFactory(Type type, data){ switch(type){ …
user102232
  • 33
  • 4
2
votes
1 answer

I am building a Weather app with Flutter and I am stuck with this error "The instance member 'widget' can't be accessed in an initializer. "

I am building a Weather app with Flutter and for this I have to transfer location data from one screen to another screen i.e from splash screen to welcome screen and from welcome screen to main_screen_navigation which has my bottom navigation bar…
2
votes
2 answers

ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Null check operator used on a null value

Hi Everyone i am facing an issue (null check operator used on null value) when i remove this operator it gives me Error here is my code Future getDirectionDetails() async { var pickUpDetails = Provider.of(context, listen:…
2
votes
1 answer

Nullable datatype check doesn't work with string interpolation

The following code is valid in Dart 2.12.4: String? firstName, lastName; firstName = 'John'; bool firstNameIsNullableString = firstName is String?; // true bool lastNameIsNullableString = lastName is String?; // true bool firstNameIsString =…
Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
2
votes
2 answers

How to convert Json inside jsonList into Dart model?

I have been trying to convert JSON to Dart using Code generation. I want to assign List into the messages variable but I'm not able to make this done. How is it possible to convert the messages into MessagesModel in the user class? import…
Leskeboy
  • 107
  • 1
  • 1
  • 9
2
votes
0 answers

Error in flutter project build gradle problem

What went wrong: A problem occurred configuring root project 'android' Could not resolve all artifacts for configuration ":classpath Could not find com.android.tools.build:gradle:6.7. Searched in the following…
2
votes
1 answer

The named parameter 'title' isn't defined.\nTry correcting the name to an existing named parame with the name 'title'.",

my fried is making a traveller app then we face this error in every title line(The named parameter 'title' isn't defined.\nTry correcting the name to an existing named parameter's name, or defining a named parameter with the name 'title'.",) …
2
votes
3 answers

I'm making a bool condition for search and review cart page

I'm making a bool condition for search and review cart page then i face these 3 errors i try to solve but not success(first 2 error on container //Expected to find ','. //The element type 'bool' can't be assigned to the list type 'Widget'. )and the…
2
votes
1 answer

('Widget? Function(BuildContext)') isn't a valid override of 'SearchDelegate.buildResults' ('Widget Function(BuildContext)')

We have recently migrated our app to null safety and now our SearchDelegate is returning the below error 'AddressSearch.buildResults' ('Widget? Function(BuildContext)') isn't a valid override of 'SearchDelegate.buildResults' ('Widget…
Boss Nass
  • 3,384
  • 9
  • 48
  • 90
2
votes
1 answer

Return type, 'FutureOr', is a potentially non-nullable type in Flutter

I am using Flutter and trying to create a database and to use bloc for state management as shown the below code: late Database database; List tasks = []; Future createDatabase() async { database = await…
Wassim
  • 23
  • 3
2
votes
1 answer

Notification channel 'basic_channel' does not exist., n.a.a.k.f.a:

As per flutter package I implemented code on my project but it threw exception while making build, "Notification channel 'call_channel' does not exist., n.a.a.k.f.a:". I don't understand why it's happen? Here is my code. …
Kodala Parth
  • 243
  • 1
  • 2
  • 12
2
votes
1 answer

Nullability mismatch in simple assignment after switching to sound null safety

I switched to sound null safety and started getting runtime error in a simple assignment, that should never happen with sound null safety: final widgetOnPressed = widget.onPressed; Error: type '(LogData) => void' is not a subtype of type…
polina-c
  • 6,245
  • 5
  • 25
  • 36