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
3
votes
0 answers

Flutter remove null values from list

I have a List of optional DateTimes. So the List can actually have null values inside. But now I need to remove all these null-values, to get a List. How is that possible? I tried it like this: …
Chris
  • 1,828
  • 6
  • 40
  • 108
3
votes
3 answers

Dart "--no-sound-null-safety" flag not working

I am trying to run a dart file without null safety using the command line. The file is: sandbox.dart void main() { String a; print(a); } I then run the file using: $ dart --no-sound-null-safety run sandbox.dart This is described…
Yahya Uddin
  • 26,997
  • 35
  • 140
  • 231
3
votes
1 answer

Flutter null safety with fromJson

Recently migrating to Flutter null safety feature, I have a lot of Classes that I need to update. For my models, I use fromJson to deserialize the data from a json object. This forces me to put the late keyword for each field that is non…
Scaraux
  • 3,841
  • 4
  • 40
  • 80
3
votes
4 answers

Navigator blocks communication between CustomScrollView and NestedScrollView

Expected behaviour: The nested scroll view scrolls normaly if the custom scroll view gets scrolled and thus scrolls the appbar with it. Actually happening: Only the custom scrollview scrolls, but not the appbar (=nested scrollview). Wanted Behaviour…
Ares
  • 41
  • 2
3
votes
2 answers

Flutter2 Upgrade: Why build_runner package is not null-safe

I'm trying to upgrade my Flutter project to Flutter2. I see all my packages are null-safe but bulid_runner. $ flutter pub outdated --mode=null-safety Showing dependencies that are currently not opted in to null-safety. [✗] indicates versions…
bianca
  • 7,004
  • 12
  • 43
  • 58
3
votes
2 answers

Flutter - Nullability problem with Locale

Below code has no compiler warnings or errors. Running it results in: lib/main.dart:26:51: Error: The argument type 'Locale?' can't be assigned to the parameter type 'Locale' because 'Locale?' is nullable and 'Locale' isn't. - 'Locale' is from…
Jemolah
  • 1,962
  • 3
  • 24
  • 41
3
votes
3 answers

How to sort a list that could contain null values with dart null-safety

I have a list of strings that may contain null values, how do I sort this list? I'm using Flutter beta channel so null-safety is checked. This is what I have so far: List _list = [ 'beta', 'fotxtrot', 'alpha', null, null, …
Brandon Pillay
  • 986
  • 1
  • 12
  • 28
3
votes
0 answers

The parameter can't have a value of null because of its type, after enabling non-nullable feature

class MyPage extends StatelessWidget { MyPage({Key key}) : super(key: key); // error in this line @override Widget build(BuildContext context) => Container(); } This code had no error before but now it's showing me key can't have a value of…
iDecode
  • 22,623
  • 19
  • 99
  • 186
2
votes
2 answers

Showing Error while using Singlechildview widget - Flutter

I created this screen and right now while I use keyboard to type the email or password, it showed overflow error and the button element is hidden and not accessible to me. I searched and used SingleChildScrollView and then the entire screen just…
2
votes
1 answer

I have a problem with null safety in flutter

I'm having a problem with null safety in Flutter, I want to put my data inside horizontal_data_table in Flutter, and I call it with StreamBuilder but when I call it inside the widget, it shows the error: The property 'paidLeaveTypeName' can't be…
1988
  • 309
  • 2
  • 15
2
votes
3 answers

Null check operator used on a null value in my flutter project

Null check operator used on a null value in calendar! i am assigning calendar with ? mark then the this null operator error is occurring and when i am adding the late calendar LateInitializationError: Field '_calendar@94028380' has not been…
bino arin
  • 123
  • 10
2
votes
1 answer

Why am I getting the Equatable error: The element type can't be assigned to the list type 'Object'

I upgraded Flutter to v 3.3.4 and am trying to fix the null safety issues with my blocs, but have run into a problem with Equatable props. When I make one of the event properties nullable, the equatable get props shows the following error on the…
user3735816
  • 225
  • 2
  • 11
2
votes
1 answer

is there a way to help me fix the type null is not a subtype of type Map?

I have been working on flutter for few months now, and I got to understand how to fix null safety issues but this one is really complicated for me and i would like to get helped. Here is my problem: Whenever I am trying to sign in, I am getting…
2
votes
3 answers

How to do null/empty check of a String inside a TextFormField validator function in dart/flutter?

Is there a shorter way to check if a string is either null or empty? Do I need to write every time 2 conditions inside if to check it? validator: (value) { if (value == null || value.isEmpty){ //.... } } In python we can do if value…
2
votes
2 answers

Null Check Operator used on null value - flutter

I am creating a drawer in flutter but whenever I click on the menu to open it, I get a Null check operator used on a null value error. What could be wrong? final scaffoldKey = GlobalKey(); // the scaffoldKay variable …
Kennedy Owusu
  • 5,690
  • 4
  • 15
  • 20