Questions tagged [null-safety]

96 questions
10
votes
3 answers

"The argument type 'String?' can't be assigned to the parameter type 'String'" when using stdin.readLineSync()

i'm new at dart. I don't know what kind of mistake i have made, but this code didn't work. Is a simple code, just read the age in terminal and say it's underage or over 18. import 'dart:io'; main(){ print("Entre com a sua idade: "); var input…
Bruno Proença
  • 113
  • 1
  • 4
6
votes
2 answers

Null-aware .firstWhere, .singleWhere, .lastWhere in Dart's List?

I often use .firstWhere((E element) -> bool) -> E in my project. When porting it to support null safety I couldn't cleanly handle a scenario when an element is not found in a List instance. .firstWhere, .singleWhere and .lastWhere returns E, not E?…
Marcin Wróblewski
  • 811
  • 1
  • 10
  • 25
3
votes
3 answers

The argument type 'List?' can't be assigned to the parameter type 'List'

Currently, I am working on updating the codebase for a Flutter project which was developed on previous versions. The error occurred once we updated to the latest version of Dart and Flutter. The code here is related to when we are returning the list…
cleopatez
  • 197
  • 1
  • 1
  • 17
3
votes
2 answers

Dart/Flutter widget with optional parameters but at least one required

I'm trying to create a Flutter widget that can be initialized by various parameters, something like this class MyWidget extends StatefulWidget { final int? id; final String? username; MyWidget({this.id, this.username}); @override …
Razvan Fulea
  • 437
  • 4
  • 13
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
0 answers

Is using @Nonnull (javax) on entities with Hibernate a bad idea?

We are using Hibernate in our Spring Boot application. Whenever we can, we use @javax.annotation.Nonnull and @javax.annotation.Nullable annotations to help us and the IDE identify, whether we can expect null values from…
basseur
  • 153
  • 1
  • 1
  • 11
2
votes
1 answer

A value of type 'StreamSink' can't be returned from the function 'assessmentSink'

class AssessmentBloc { late AssessmentRepository _genRepository; late StreamController assessmentController; late StreamController submitAssessmentController; StreamSink> get assessmentSink =>…
FatahZull
  • 43
  • 7
2
votes
2 answers

Why does being null safe matter

I'm currently in the process of switching over from java to kotlin and one of the stated advantages that keeps popping up is that kotlin is Null safe and by default cant have variables or objects be assigned a null value but there are ways to assign…
2
votes
1 answer

Dart closure return type problem after migrating to null safety

The below code used to work before migrating to Flutter 2 and null safety. I just can't figure out what the correct return type should be. The error I get is: The return type 'List?>' isn't a 'List>',…
Ernesto
  • 103
  • 1
  • 8
2
votes
0 answers

Conflict with null safety with Null check operator used on a null value

I have a problem with null safety. i want to create the functions onFieldSubmitted and onChanged in my class like below import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:rift/constants.dart'; class…
ellen100311
  • 67
  • 1
  • 6
2
votes
2 answers

How to initialize Either Right to an empty value in flutter

I recently made the switch to null-safety in my flutter project, which brings a new kind of problem when using the Either type (from the dartz package) For example, before I would have some properties in my class like this: Either
Manu
  • 372
  • 2
  • 12
2
votes
2 answers

Animatable TweenSequence throwing error in Null Safety

I just migrated my flutter app in Null Safety. Everything seems to be working well, except the below code: Animatable animColorPend = TweenSequence([ TweenSequenceItem( weight: 1.0, tween: ColorTween( begin:…
oupoup
  • 75
  • 8
1
vote
1 answer

Null Safety Error: Unconditionally accessing 'state' property in Flutter Riverpod

I'm encountering a null safety error in my Flutter Riverpod code when trying to access the 'state' property. The error message says: "The property 'state' can't be unconditionally accessed because the receiver can be 'null'. Try making the access…
caroch
  • 105
  • 5
1
vote
0 answers

The app was working fine and after the latest update to flutter it is giving this error

I hope to solve this error because most of the applications that I work on are giving the same or similar error I tried downgrading the sdk to a lower level but it gives the same error " The current Dart SDK version is 2.19.0-146.2.beta. Because…
1
vote
2 answers

Why do I get this error: _CastError (Null check operator used on a null value)

I have a column like this: Column(children: [ product.videos![product.videoIndex].videoUrl != null && product.videos![product.videoIndex].videoUrl != "" ? VideoPlayerWidget( videoAddress:…
best_of_man
  • 643
  • 2
  • 15
1
2 3 4 5 6 7