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

Periodic Error in Flutter: Unhandled Exception: Null check operator used on a null value

As soon as I start my App (it happens both in debug and profile mode), the following error occurs: [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value E/flutter (12391): #0 State.setState…
Arveni
  • 68
  • 6
0
votes
1 answer

How to handle null safety for File in flutter?

I am working with Firebase and I have submitForm method like this: // File variable declaration File? _userImageFile; void _submitForm() { try { final isVaild = _formKey.currentState!.validate(); // To close soft keyboard …
Divyesh
  • 2,085
  • 20
  • 35
0
votes
1 answer

l10n migration to null safety

I'm trying to migrate my Flutter/Dart project to Null Safety. When I run dart pub outdated --mode=null-safety It appears that all my dependencies support null-safety Showing dependencies that are currently not opted in to null-safety. [✗]…
David L
  • 1,134
  • 7
  • 35
0
votes
2 answers

Null check operator used on a null value - BloC with Null-Saftey

I tried to understand why topRated and popular always get null value although results print it's value in console I'm using The Movie DB Api import 'package:expandable/expandable.dart'; import 'package:flutter/material.dart'; import…
0
votes
1 answer

The method 'toInt' can't be unconditionally invoked because the receiver can be 'null' in Dart

I am trying to add duration to a Timestamp in flutter. onPressed: () async { final String? activity = _activity.text; final double? slno = double.tryParse(_slno.text); final double?…
0
votes
2 answers

Better way to assign a value with nullable field in dart

Is there a better way to do this? Assignment( dueAt: json['due_at'] == null ? null : DateTime.parse(json['due_at']).toLocal() ) The attribute "dueAt" in Assignment class can be null and i need to parse the string of…
miguelps
  • 142
  • 3
  • 9
0
votes
1 answer

Why BlocProvider Gets this two errors with null-safety?

Error No.1 : error: 'Null' doesn't conform to the bound 'BlocBase' of the type parameter 'T'. (type_argument_not_matching_bounds Error No.2 : error: Couldn't infer type parameter 'T'. Tried to infer 'Null' for 'T' which doesn't work: …
0
votes
0 answers

Null check operator used on null value error even if I didn't use any

This is the widget the error is pointing to Container( height: 350, child: GetBuilder( id: imageContainer, builder: (_) { if…
0
votes
1 answer

Null check operator used on null value when I have defined a model the particular list using null safety in flutter

I want to check if list is empty then show some image and if it is not I want to show the contents of the list but I am getting an error when checking if the list is empty.This is my model class import 'dart:convert'; class ProductModel { …
0
votes
4 answers

Flutter Firebase Database, DataSnapshot? how to get values and keys, null safe

Using firebase_database: ^7.1.1 Before null safety i used to do like this to get the data from firebase database: DataSnapshot dataSnapshot = await References.getReferenceYears().once(); Map values =…
Jorge Vieira
  • 2,784
  • 3
  • 24
  • 34
0
votes
1 answer

The property 'docs' can't be unconditionally accessed because the reciever can be 'null'

When I use this code: return FutureBuilder( future: searchResultsFuture, builder: (context, snapshot) { if (!snapshot.hasData) { return cargandoCircular(); } List searchResults = []; …
user16416358
0
votes
1 answer

In the absence of a `pubspec.yaml` file, what determines whether I'm opting in to null safety?

I understand that if I cd /tmp and then dart create code, I get environment: sdk: '>=2.10.0 <3.0.0' in /tmp/code/pubspec.yaml, which tells me that even though I'm running Dart v. 2.12.3, this (default) configuration does not opt into null…
Sam
  • 563
  • 5
  • 15
0
votes
2 answers

Dart Null Safety: The method '[]' can't be unconditionally invoked because the receiver can be 'null'

I have got the following Text( ... ) widget in my Flutter application Text( data['location'], style: TextStyle( fontSize: 40, …
John Doe
  • 87
  • 1
  • 9
0
votes
1 answer

Unable to save the data in model from firestore after migrating to null safety

So, I have a user model where i want to store the value from the document present in firestore and for that i have the following code:- import 'package:cloud_firestore/cloud_firestore.dart'; class UserModel { final String? id; final String?…
Deepak Lohmod
  • 2,072
  • 2
  • 8
  • 18
0
votes
1 answer

Migarting a flutter project to null safety fails with `RangeError (index): Invalid value: Valid value range is empty: 0`

I'm trying to migrate my project to null-safety but the process crashes right after compiling instrumentation information step. The error I keep getting is not really helpful and doesn't point me to where the issue is taking place. Here's the error…
moazelshebly
  • 145
  • 9