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

How does null assertion work in dart and when can I use it?

Can someone simply explain to me how null assertion (!) works and when to use it?
rebix
  • 78
  • 5
-1
votes
1 answer

What is the right way to fetch list array json in lisview flutter with sound null safety?

As Flutter introduced sound null safety feature. I just want to know is there any right way of coding standard we need to follow while integrating rest apis with flutter null safety?
Vinay Bakle
  • 133
  • 13
-1
votes
3 answers

'Null' is not a subtype of type 'String'

Error: 'Null' is not a subtype of type 'String' if (loginProvider.errorMessage != true) Container( color: Colors.amberAccent, child: ListTile( title: Text(loginProvider.errorMessage), leading: Icon(Icons.error), …
noob
  • 1
  • 2
-1
votes
1 answer

How to identify final or dynamic value properties is bool or int in Flutter

// FirstScreen final result = await Get.to(SecondScreen()); //SecondScreen //First button onTap Get.back(result: 10) //second buton onTap Get.back(result: true); How can I identify the result is bool or int type when back to the second…
-1
votes
6 answers

The operator '>' can't be unconditionally invoked because the receiver can be 'null'

I have just upgraded to sound null safety and having trouble making this condition work. How can I check the length on a nullable variable? Though the error makes total sense, if the event.newPhone is null it cannot perform the check, any suggestion…
Manas
  • 3,060
  • 4
  • 27
  • 55
-1
votes
1 answer

dart null-safe list declaration

I wanted to use this pin code field generator, but parts of it are deprecated. _pin = List(widget.fields); _focusNodes = List(widget.fields); _textControllers = List(widget.fields); (widget.fields is an…
Ugur
  • 312
  • 5
  • 15
-1
votes
1 answer

Dart fold with null safety

I have the following code that sums cash for people with the same name using list fold. void main() { List> people = [{'name': 'Jim', 'cash':44.86},{'name': 'Jim', 'cash':40.55},{'name': 'Bob', 'cash':10.99},{'name': 'Bob',…
ssmc
  • 21
  • 6
-1
votes
1 answer

Let TextEditingController be null in null_safety

I have converted my project to null-safety Dart 2. I have been working through issues since the conversion. Right now, I need to change this line clientFNameController.text = widget.trxns!['clientFName']; so that clientFNameController.text =…
LostTexan
  • 431
  • 5
  • 18
-1
votes
1 answer

How to take integer input in dart after the null safety update without using the if block for veriying weather the variable is null or not?

Every time i need to input certain variable as integer i used to use this below code for that import 'dart:io'; void main(List arguments) { int a = 0; print("Enter a :"); String? x = stdin.readLineSync(); if (x !=…
REtr0
  • 17
  • 2
  • 6
-1
votes
1 answer

I have 3 issues from migrating to null-safety

I migrated to null-safety today and I have 3 issues that I don't know how to fix. Below, I have provided the errors and the code that each error refers to. I do not know how to fix these issues and they are the only errors left. error • The body…
LostTexan
  • 431
  • 5
  • 18
-1
votes
1 answer

Dart: argument type "List
" can't be assigned to the parameter type "List
?"

I have a copywith method I'm trying to use like this in a qubit... final sections = await getSections(_database.getInstance(), _projectID, zoneID); emit(state.copyWith(sections:sections)); And I keep getting an assignment error but when I do the…
user2561417
  • 295
  • 4
  • 13
-1
votes
1 answer

Fetch JSON with Flutter and NULL safey

My JSON is updating over time, at start, I may have Null value, but like 15 minutes later, I may have something. How can I do my Class with null safety ? I have this error when I create the class.
-1
votes
1 answer

Flow analysis doesn't work when using setState

void f() { String string; setState(() { string = fooCondition ? 'foo' : 'bar'; }); string.toUpperCase(); // Error } If I remove the setState condition, the flow analysis work! I could put my setState below (blank setState(() {}) but…
iDecode
  • 22,623
  • 19
  • 99
  • 186
-1
votes
1 answer

DropdownButton error: The argument type 'void Function(String)' can't be assigned to the parameter type 'void Function(String?)?'

I started seeing this error in my DropdownButton after migrating to null safety. DropdownButton( value: myValue, onChanged: (String string) { // Error print(string); }, items: [ DropdownMenuItem( value: 'foo', …
iDecode
  • 22,623
  • 19
  • 99
  • 186
-1
votes
3 answers

The argument type 'Widget' can't be assigned to the parameter type 'PreferredSizeWidget?' in null safety

Scaffold( appBar: _buildAppBar(), ) Here's the function: Widget _buildAppBar() => AppBar(); // Error This code was working fine until I migrated my code to null safety.
iDecode
  • 22,623
  • 19
  • 99
  • 186