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

Inheritance on Dart Null Safety for testability

I have a question related to Dart Null Safety concept. Imagine I have a class called Bird class Bird{ Object character; Bird(); } and Pigeon class Pigeon extends Bird{ String name; Pigeon(); } Now, because of Null Safety on Dart, the character…
Darari Nur Amali
  • 465
  • 3
  • 13
0
votes
1 answer

Can I still migrate current project to support null-safety while some of the dependencies not support it yet?

It would take too long to wait until all dependencies to support the null-safety. So I am thinking not to wait for them. I wonder if I can do or should do that.
Chanin
  • 31
  • 1
  • 5
0
votes
1 answer

How to debug the Null Safety default value type error on double question mark '??'

I recently run into some strange behavior when using double question mark. Here is the example code: void main() { String strA; String strB; print('start'); strB = strA ?? 5; // wrong use of default value type. It should be a String here. …
yellowgray
  • 4,006
  • 6
  • 28
0
votes
1 answer

Why can a variable declared using 'var' be null in null-safe dart?

I'm copying this from the docs // In null-safe Dart, none of these can ever be null. var i = 42; // Inferred to be an int. String name = getFileName(); final b = Foo(); But I'm running the code below in a null-safe dartpad, and it compiles. void…
Abdou Ouahib
  • 821
  • 5
  • 14
0
votes
1 answer

What's the difference between ? and ! in collections like Map, List and Set?

What's the difference between ? and ! when used in a collection in Dart? Say, I have: var list = [1, 2]; Now, I can either use print(list?[0]); // prints 1 or print(list![0]); // also prints 1 Both of them seems to do the same job, so what's the…
iDecode
  • 22,623
  • 19
  • 99
  • 186
0
votes
1 answer

Flutter - NoSuchMethodError: The getter 'isNotEmpty' was called on a null

It is a world time app that starts with a home screen showing a default location at the beginning then you can change the location and the API gets you the time on that new location. It works fine but when I hit the back button in the "location" bar…
-1
votes
3 answers

Removing elements from a list where several nested values are null or empty in dart and flutter

I want to get my contacts from my phone and save them into firebase. The following code works if all I wanted to do is save the contact name, mainly because the name cannot be empty in the phone but a problem arises when the nested…
user2818170
  • 107
  • 1
  • 10
-1
votes
1 answer

how to create a dynamic form backend in flutter

This is my backend data This is my form screen how can I get the control value of these dynamic fields class DyDataList with ChangeNotifier { final List _dyDataList = [ DyData( filedName: "Full Name", control: "TextBox", …
-1
votes
1 answer

Flutter Sqflite Toggling between Screens based on Login Status creates null operator used on null value error

I am trying to toggle between Login Screen and HomeScreen based on the user status. The logic seems to be working as long as I don't put HomeScreen. I replaced HomeScreen with a different screen to check and the app works as it should. It displays…
mohitnx
  • 11
  • 1
-1
votes
1 answer

I want to get json from api in flutter

class Phone{ int? id; bool? is_new; String? title; String? subtitle; String? picture; bool? is_buy; dynamic best_seller; int? price_without_discount; int? discount_price; Phone({ this.id, this.is_new, this.title, this.subtitle, …
Edgar A8
  • 3
  • 3
-1
votes
1 answer

Why is this null error showing up in my localization structure when loading maps that should initialize?

Can someone point out why I'm getting a null error where loading text within my localizations structure. Error commented below at authSighInText. The only thing I can think of is that _localizedValues is not initialized yet upon app launch. Should I…
RobbB
  • 1,214
  • 11
  • 39
-1
votes
1 answer

How to Enable/Disable two Elevated Button in Flutter one after another?

I have two elevated buttons I want to disable if I click the A button and disable the B button if I click the B button then need to disable button A.
Anee
  • 49
  • 6
-1
votes
4 answers

LateInitializationError: Field 'email' has not been initialized

i am trying to get the text kept in the validator property in the TextFormField to show in the app but for some reason, it keeps keeps giving me the LateInitializationError: Field 'email' has not been initialized. even though i have initialized my…
alex
  • 5
  • 7
-1
votes
3 answers

error: This expression has a type of 'void' so its value can't be used

import 'package:flutter/material.dart'; class Utils{ static final messengerKey = GlobalKey(); static showSnackBar(String? text){ if (text == null) return; final snackBar = SnackBar(content: Text(text),…
-1
votes
1 answer

The argument type 'String?' can't be assigned to the parameter type 'String'. in carousel image flutter model -

I'm gettin stuck in put my image carousel from model carousel_model.dart enter image description here enter image description here//i.stack.imgur.com/Qp92R.png