Questions tagged [non-nullable]

232 questions
1
vote
1 answer

Android's MutableLiveData should use nullable objects only?

My simplified code is: class MyViewModel : ViewModel() { private val myLiveData: MutableLiveData = MutableLiveData(MyObject()) val myObject: MutableLiveData get() = myLiveData fun addItem(item:…
ocramot
  • 1,361
  • 28
  • 55
1
vote
1 answer

The method 'cancel' can't be unconditionally invoked because the receiver can be 'null'

I have the following code: class Auth with ChangeNotifier { String? _token; DateTime? _expiryDate; String? _userId; Timer? _authTimer; String? get token { if (_expiryDate != null && _expiryDate.isAfter(DateTime.now()) && …
user11874694
1
vote
4 answers

A value of type 'Null' can't be returned from the function ' ' because it has a return type of 'String'

I am following a flutter tutorial uses the following codes class Auth with ChangeNotifier { late String _token; late DateTime _expiryDate; late String _userId; late Timer _authTimer; String get token { if (_expiryDate != null && …
user11874694
1
vote
1 answer

Error:-The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type

I am currently building a botcoin ticker app that returns a list of currencies to a dropDown menu . I am getting the following errors:- error: The body might complete normally, causing 'null' to be returned, but the return type is a potentially…
Karthik KK
  • 157
  • 1
  • 11
1
vote
1 answer

Define type that is no longer undefined after data fetched Typescript

Is there a way to tell TypeScript, that a certain type is no longer nullable if a certain call has been made in the code before? So for example I have a call to an API and afterwards I know that the data is defined. But this call is happening…
uloco
  • 2,283
  • 4
  • 22
  • 37
1
vote
1 answer

Argument type String? can't be assigned to the parameter type 'String'

With the code below I get the following error message: The argument type 'String?' can't be assigned to the parameter type 'String'.dart(argument_type_not_assignable) The part of the code producing the error (at least I think it does) is the…
sboom
  • 37
  • 4
1
vote
0 answers

Eclipse @NonNull annotation not using eaa files?

We've been using the Eclipse @NonNull and @Nullable annotations in our big Java app for a while. I'm trying to setup a new project in eclipse to use them - but can't seem to get the same results. (Note: Previous projects were setup by somebody that…
CasaDelGato
  • 603
  • 7
  • 17
1
vote
1 answer

Flutter nullable error when creating class parameterized constructor

I updated flutter stable version 2.2.1 (Nullable feature enabled). When I write constructor of the class as following code, I got error as following image shows. Please help me to resolve this. class FlavorBanner extends StatelessWidget { final…
Malisha De Silva
  • 393
  • 2
  • 10
1
vote
2 answers

Does a function without a return statement always return null in Flutter?

The return type of the following function is Future and yet the compiler does not complain that there is no return value if the picker did not return a picture. static Future takeImage() async { PickedFile? pickedFile = await…
Joel Broström
  • 3,530
  • 1
  • 34
  • 61
1
vote
1 answer

EF4 mapping nullable decimal column to non-nullable value property

I am using POCOs (no proxies) with EF4. In the database, I have this nullable decimal column: On my POCO, I have this non-nullable value property: public decimal Amount { get; set;…
1
vote
0 answers

Non nullable reference types: can I define a default element?

I work with C# 8 with non nullable reference types and I define a class MyClass: class MyClass { public int Prop1 { get; set; } = 0; public bool Prop2 { get; set; } = false; } I want to create an array var myArray = new MyClass[10]; Since…
xavier
  • 1,860
  • 4
  • 18
  • 46
1
vote
1 answer

Cached network image is throwing errors after using non-nullable in flutter

Currently using Non Nullable for flutter, all the dependencies work fine except for cached_network_image. My pubspec.yaml: environment: sdk: ">=2.10.0 <3.0.0" dependencies: flutter: sdk: flutter cached_network_image: ^2.3.3 In my…
1
vote
1 answer

Kotlin : if String is null and double bang(!!) operator is used, why does it give compile error for length function?

example: fun main(){ var userInput: String? //userInput = null userInput = "asbdef" var inputLength:Int? = userInput!!.length println("Length of the string is :"+inputLength) } Output : Length of the string is :6 fun main(){ …
1
vote
1 answer

This requires non-nullable language feature to be enabled — Dart non-nullable syntax error

I've activated Dart non-nullable syntax experiment in my pubspec.yaml file: name: tests description: A new Flutter application. publish_to: 'none' version: 1.0.0+1 environment: sdk: ">=2.9.0-21.0.dev.flutter <3.0.0" analyzer: …
1
vote
1 answer

Inferred type is Collection of nullables but expected Collection of non-nullables

I intended to process some data (it's a list of parsed from json objects Nuu, in the example below I just stubbed the list). To process that collection I pass a consumer println into the method getAllNuu that retrieves and parses that…
exenza
  • 966
  • 10
  • 21