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
1 answer

_TypeError (type 'Null' is not a subtype of type 'FutureOr')

Have recently installed Flutter null safety and having fixed most of the code I am having trouble with an API call. It returns _TypeError (type 'Null' is not a subtype of type 'FutureOr') I haven't found a SO answer that seems to line up…
al246
  • 220
  • 6
  • 16
0
votes
1 answer

I am trying to save the notification title and body using shared preference but i am unable to

#I am trying to save the notification title and body locally and fetch the title and body inside my app to show all the sent notification in a listview but i am unable to #this is the code i am running this code in my main.dart inside initstate and…
Saurav
  • 132
  • 1
  • 12
0
votes
1 answer

The function call is not returning null but still giving "null" to be returned error

I'm migrating my old version flutter code to latest version with null safety feature. In a function call I am getting the error "The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable…
Dev94
  • 757
  • 6
  • 24
0
votes
2 answers

The method '[]' was called on null. Receiver: null Tried calling: []("main") console error

Hi i am working on a weather app i learnt from a course, everything was working fine till i start with the refactoring and it just got complicated the code show no error but when i hot restart the app it crash showing The method '[]' was called on…
0
votes
2 answers

Flutter Null Safety and Firebase authentication error

I am using flutter and firebase for my app. I don't know why I am getting error in below code. With degrade version of flutter(Without null safety) it is working fine but after migrating over null safety, I am facing problem here. class…
Harry
  • 154
  • 4
  • 15
0
votes
1 answer

Error: The argument type 'User?' can't be assigned to the parameter type 'User' because 'User?' is nullable and 'User' isn't. *(NullSafety)*

I'm taking a course for Flutter and I think the course is a bit old, I'm trying to upgrade an old code to null safety, but since I'm just starting to learn null safety, I'm encountering errors and I couldn't figure out why, I would be glad if you…
0
votes
4 answers

Dart check if many variable is null

Hello im new in dart language, is someone can help me to write this condition better, it works but it's a lot repetitive and i feel theres a better ways to write it : if (var1 != null || var2 != null || var3 != null || var4 != null || var5 !=…
0
votes
4 answers

Dart null safety !. vs ?-

what is the difference exactly between String id = folderInfo!.first.id; //this works and String id = folderInfo?.first.id; //this is an error I know ?. returns null when the value object is null but what does the !. return?
Paul Cbt
  • 125
  • 8
0
votes
2 answers

json.decode to List> issue in flutter

snap shot from the code Hello I am trying to get Data from API And put it inside List> I use a several ways but they doesn't work In the image the data saved in the variable but when i use foreach it ignore the index 0 I try to…
0
votes
0 answers

flutter geolocator: ^8.0.1 not working properly

I was trying to use geolocator in my flutter project but i keep getting the following error code when i restart the app: This is my flutter code below: import 'package:flutter/material.dart'; import 'package:geolocator/geolocator.dart'; class…
0
votes
1 answer

+ isn't defined for the type 'Object

I keep getting this error => "The operator '+' isn't defined for the type 'Object'. (view docs). Try defining the operator '+'." How could I define it? import 'dart:math'; bool isArmstrongNumber(int number) { var numberString =…
Carlos
  • 3
  • 1
0
votes
1 answer

type 'Null' is not a subtype of type 'AuthViewModel' in type cast

Im trying to build a Google sign in page and i got this error : type 'Null' is not a subtype of type 'AuthViewModel' in type cast , i dont know what to doh ere I tried to solve it but nothing worked and vscode didnt thro any errors till i run the…
Yousif 304
  • 23
  • 4
0
votes
1 answer

Why is Flutter building without sound null safety

My pubspec.yaml has environment: sdk: '>=2.15.0-116.0.dev <3.0.0' When I run flutter build appbundle/apk it prints Building without sound null safety For more information see https://dart.dev/null-safety/unsound-null-safety Running Gradle task…
iDecode
  • 22,623
  • 19
  • 99
  • 186
0
votes
2 answers

how to create draggable scrolling bottom sheet inside google maps scaffold in flutter?

I want to create a draggable scrolling bottom sheet like this! here is the design there will be a button on the top left to go back, there will be a button on the top left to go back, and there is a draggable bottom sheet should I use the…
0
votes
1 answer

I have a problem in my flutter app. For some reason I can't run any of my flutter files. Every time I try to run it keeps giving me an error message

C:\Users\omar\src\flutter.pub-cache\hosted\pub.dartlang.org\geolocator_android-3.0.1\android\src\main\java\com\baseflow\geolocator\location\LocationMapper.java:29: error: cannot find symbol if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)…