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
0
votes
1 answer

Flutter Unhandled Exception: Stack Overflow on cloud_firestore after hot reload

Currently working on a Flutter Firestore after updating to latest version it start causing the problem The application works good but when i click hot reload it start displaying this error. I thought there might be a problem in cache. So I did…
0
votes
2 answers

Why are Dart null-safety problems showing up inconsistently in 2 places

I have a flutter app. I'm using VSCode. When I do the following I get the following error reported in two places (the 'PROBLEMS' area and in the 'Debug Console': faulty code: bool fff = (preferences?.getBool("_wantSpaces")); error msg: "message":…
user2429448
  • 541
  • 1
  • 5
  • 14
0
votes
0 answers

LateInitializationError: Field 'annotationAst' has not been initialized

I upgrade my packages using dart pub outdated --mode=null-safety command. after updating my packages I got this error while running dart migrate to migrate my code to null-safety. also when I tried to run flutter pub run build_runner build…
DNS
  • 851
  • 11
  • 19
0
votes
1 answer

null safety error when creating Flutter classes and widgets

I am learning Flutter / Dart and when doing the exercise in this video I have encountered an error that from what I understand is due to the null-safety feature and because the example is from a previous version, the problem appears . import…
Diego Aaron
  • 386
  • 1
  • 6
  • 19
0
votes
2 answers

How to set current location as initialPosition in PlacePicker with GoogleMaps - Flutter

How do i change initialPosition in PickerPlace to current position? I would like the user's location to be displayed at the start I'm currently using geolocator, google_maps_flutter I would have to give the currentPosition in initialPosition but I…
0
votes
0 answers

How to return empty abstract class data set (PostgreSQLResult)?

I am trying to rewrite my code to make is null safety. PostgreSQLResult getResultFromCache(sqlQuery) { for (var req in requestsCacheList) { if(req.requestHash == sqlQuery.hashCode) { return req.requestResult; } } //…
Dmitry Bubnenkov
  • 9,415
  • 19
  • 85
  • 145
0
votes
2 answers

Flutter 2: From List null safety create a children row with mapIndex

Since the update of flutter of null safety I don't understand anything of what is happening. I am trying from a list on a children to create a Row of icons but I don't succeed (here the mapIndex can't be used because of the null safety (whereas in…
Da2ny
  • 897
  • 2
  • 9
  • 24
0
votes
1 answer

Creating 2D array in Dart where only row length is defined

I want to implement below piece of code(Java) in Dart/Flutter. Could you please tell me how to achieve this.? Here rows = 8, colums = not defined. int[][] myArray = new int[8][];
0
votes
2 answers

Upgrading Firebase User model to null safety

I've finally taken the plunge to upgrade my app to Null Safety, but am having problems upgrading the following code. (If not obvious, I'm mapping the Firebase User model to a local AppUser model, and using this as authentication wrapper around the…
0
votes
2 answers

Flutter Error -> Non-nullable 'items' must be initialized

class CatalogModel { static List items; static Item getById(int id) => items.firstWhere((element) => element.id == id, orElse: null); static Item getByPosition(int pos) => items[pos]; } I'm trying to create the class with a static…
0
votes
3 answers

Arg type 'String? Function(String)' & 'void? Function(String)' can't assigned to param type String? Function(String?)? and void? Function(String?)?

I am getting argument type not assignable error in dart while checking the email value is empty or not the error which I am getting are The argument type void Function(String) can't be assigned to the parameter type void…
Mithson
  • 1,554
  • 13
  • 33
0
votes
2 answers

Unhandled Exception: type 'Null' is not a subtype of type 'Future'

i have tried to turn Future to nullable and also the string but something goes wrong any help please? floatingActionButton: FloatingActionButton( onPressed: () { getName().then((value) { print(value); throw("error!!!!!"); …
0
votes
2 answers

Is there better way to read values in a string using for loop in dart language

I am trying to write a code that ask the user for a string and print out whether this string is a palindrome or not. When code is executed it directly goes to the print statement, the for loop doesn't into the string and compare the values. …
sachi
  • 3
  • 1
0
votes
1 answer

how to handle null safety during api call flutter?

am trying to do an API call where am getting an error to hangle null safety variable must be assigned. here is my code Future loginCustomer( String username, String password) async { LoginResponseModel model; try…
naveen
  • 49
  • 1
  • 6
0
votes
1 answer

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

This so ridiculous, why I wouldn't be able to assign a non null-able value to a null-able variable? is it a null safety problem or something else? Thank you.
Hassan Kanso
  • 237
  • 1
  • 10