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
2 answers

Why flow analysis doesn't work when using bool?

void main() { int? foo; var isNonNull = foo != null; if (isNonNull) foo.isEven; // Error } I already did a check on foo and stored its value in isNonNull variable. I could understand that warning if the scope wasn't local. Note: I know I…
iDecode
  • 22,623
  • 19
  • 99
  • 186
0
votes
2 answers

How to use a List as member variable in Flutter?

I tried to define a class, which contains a List of a specific item-object, which will be populated within Constructor and will also receive new items at a later time: class Repository { final List _items = List(); Repository()…
delete
  • 18,144
  • 15
  • 48
  • 79
0
votes
1 answer

In Flutter, how to use Null Safety in Future?

I'm trying to migrate to Null Safety in Flutter. The following code snippet to convert ImageProvider to ByteData works fine without Null Safety. static Future imgProvider2ByteData(ImageProvider img) async { Completer completer =…
jdevp2
  • 371
  • 5
  • 15
0
votes
1 answer

Unhandled error LateInitializationError: Local 'failureOrSuccess' has not been initialized. occurred in Instance of 'SignInFormBloc'

Stream _performActionOnAuthFacadeWithEmailAndPassword( Future> Function({ @required EmailAddress emailAddress, @required Password password, }) forwardedCall, ) async* { Either
0
votes
3 answers

Error:The method '[]' can't be unconditionally invoked because the receiver can be 'null'

i just convert my project Null Safety and i am getting error saying The method '[]' can't be unconditionally invoked because the receiver can be 'null'. Try making the call conditional (using '?.') or adding a null check to the target ('!'). i…
Gbenga B Ayannuga
  • 2,407
  • 3
  • 17
  • 38
0
votes
2 answers

"Unhandled error Null check operator used on a null value" after await on a Future from a moor database

I am trying to learn how to implement a moor database in flutter and I got stuck getting this error: I/flutter ( 5303): Moor: Sent SELECT * FROM tasks; with args [] E/flutter ( 5303): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception:…
kforjan
  • 584
  • 5
  • 15
0
votes
1 answer

flutter null safety The argument type 'String?' can't be assigned to the parameter type 'String'

I am using null safety in my flutter app and i am trying to map a map to a walkthrough screen widget. I have looked and not seen solutions online. Here is my map final pageViewModel = [ { 'title': 'Budget Your Funds And Save Up', 'subtitle':…
Patrick Obafemi
  • 908
  • 2
  • 20
  • 42
0
votes
1 answer

Cannot get documents or docs with cloud firestore : ^2.1.0 flutter

I've just upgraded to cloud firestore: ^2.1.0 and I have an error on snapshots.data?.documents or snapshots.data?.docs with message The getter 'documents' isn't defined for the type 'Object'. in the above code : @override Widget build(BuildContext…
0
votes
0 answers

dart nullability checking method

I have a method bool isNotEmpty(dynamic e), where i check nullability myself based on few criteria (e.toString() == null.toString(), e.length for String's and List's, etc.). my question is, I have a piece of code like this: String e = 'a'; if…
Adnan
  • 906
  • 13
  • 30
0
votes
0 answers

Is there any other way of resolving null safety migration errors instead of manually?

I just updated my application and I have the following: - flutter version: 2.3.0-1.0.pre - flutter channel: dev - number of packages: 50 - migration errors & warnings: 3k+ Is there any other solution instead of fixing the migration errors manually?
0
votes
1 answer

Breaking changes with cloud_firestore 2.0?

I am using CloudFirestore with my app. Everything was working fine and since the 2.0.0 version, I encounter errors that I didn't before. Here is the code : final _fireStore = FirebaseFirestore.instance .collection('familyAccounts') …
SylvainJack
  • 1,007
  • 1
  • 8
  • 27
0
votes
2 answers

Flutter nullsafety: conditional List position

If I am not sure a list is null or not, I could do final something = myList?[0].property; What if I knew myList existed but was not sure there is an element in it? Do I need to manually check that isNotEmpty? final something =…
user3808307
  • 2,270
  • 9
  • 45
  • 99
0
votes
1 answer

Modify model to adapt to null fafety

I migrated to null safety, environment: sdk: ">=2.12.0 <3.0.0" But my ImageModel report error. class ImageModel { ImageModel({ this.total, this.totalHits, }); int total; int totalHits; factory…
Vincent
  • 3,124
  • 3
  • 21
  • 40
0
votes
1 answer

not able to complete the program

I'm new to dart and having a hard time figuring out things. so, I just need some help completing the program below. I have no idea where I'm going wrong. All I'm getting is an error related to null safety question :- Write a program to obtain a…
Bavan
  • 31
  • 6
0
votes
2 answers

The getter 'value' isn't defined for the type BehaviorSubject<>

After I updated the code to adapt flutter null safety the code below gaves me the error The getter 'value' isn't defined for the type 'BehaviorSubject'. final _brightness = BehaviorSubject(); ... if (_brightness.value ==…
rozerro
  • 5,787
  • 9
  • 46
  • 94