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

why do I get an error after trying to use firebase_core, thinking it is nullsafety?

I get the following error in my Dart Analysis: error: The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type. (body_might_complete_normally at [the_book_club] lib\main.dart:28) This is…
0
votes
1 answer

Closure call with mismatched arguments: function 'LoginScreen.build.'

Hello I'm getting this error when I tried to run the code Here is the full error: ======== Exception caught by widgets library ======================================================= The following NoSuchMethodError was thrown building…
0
votes
1 answer

Problem concerning null safety in functions

I have this function called add which adds two numbers and returns the result in dart. void main() { int step1Result = add(n1: 5, n2: 9); int step2Result = multiply(step1Result, 5); double finalResult = step2Result / 3; …
Logic
  • 53
  • 1
  • 9
0
votes
1 answer

Error: The parameter 'onSubmit' can't have a value

Hi I have created a default form field, in a separate dart file called components, and I have login_screen.dart also. there are many errors I don't know how to fix it, and make the code work, I will put down the code of the component.dart code: …
0
votes
1 answer

I have a basic question on dart function:

I have wrote a bit code in dartpad: void main() { greet('Jack'); double result = myFunction(); print(result); } void greet (String personToGreet) { print('Hello, $personToGreet) } double myFunction () { double pi = 3.1415926; return pi…
0
votes
1 answer

Why does clearing a list clear the first?

I have programmed this little example so that you understand my problem. I make a copy of a list and I am eliminating values from the copy but they are also eliminated from the original. Why does this happen? The error is: Uncaught Error: Concurrent…
PabloBazan
  • 33
  • 4
0
votes
2 answers

how to use showbottomsheet with null safety in flutter?

I'm still learning flutter new this week, seems the course is outdated, so i struggle every time I face null safety errors. Now, I can't use showbottomsheet.. tried null check(!) but onPressed() is always returning null , i can't figure what should…
0
votes
2 answers

How to get only "date" in DateTime format using syncfusion_flutter_datepicker in Flutter

What i want: I want to get only the startDate and endDate in DateTime format so that i can find the difference of days between the two dates. Instead i'm getting startDate and endDate in String format. My code: void…
0
votes
1 answer

Flutter/Dart return Future

I have a function, which I want to return a Future of String or null. For simplicity, the function will return null if delay for 1 second is success, or else it will return "failed"; However; I got the Future fcn(String str) { return…
Steven Z.
  • 47
  • 1
  • 11
0
votes
0 answers

pub get failed when upgrading the flutter version

I have upgraded the flutter version to the latest (2.5.2). when I upgrade, some dependencies also upgraded. but some of them are not compatible with null-safe. SDK version is (2.5.2), sdk: ">=2.12.0 <3.0.0" suggest versions (only incompatible…
Tharindu Lakshan
  • 3,995
  • 6
  • 24
  • 44
0
votes
1 answer

Getting null value instead of input value in flutter

I am receiving a null value when I am saving a value as in my code I have three fields String? _itemName =""; String? _dateCreated =""; int? _id; and when after running my project, I insert an item by calling this method: Future
Saad Ebad
  • 206
  • 5
  • 16
0
votes
1 answer

missing default_value_for parameter flutter

I m creating a reusable widget TextFormField. Error: Code: import 'package:flutter/material.dart'; class TextFormFieldWidget extends StatelessWidget { final TextInputType textInputType; final String hintText; final Widget prefixIcon; final…
0
votes
3 answers

Unhandled Exception: LateInitializationError: Field '_id@21016470' has not been initialized

When i am running my project compiler is giving me this statement "LateInitializationError: Field 'Db' has" i am unable to fix this issue. When i execute the functions in dabase_client.dart i.e saveItem() function then it is creating issues and…
Saad Ebad
  • 206
  • 5
  • 16
0
votes
0 answers

The operator '[]' isn't defined for the class 'Object' after migrating to null safety

I migrated my code to null safety but now I get an issue: When I want to fetch a document from firestore I get this error: Error: The operator '[]' isn't defined for the class 'Object'. Here is the code snippet where I want to call ['plans'] on the…
0
votes
0 answers

"The argument type 'Users? Function(User)' can't be assigned to the parameter type 'Users Function(User?)'."

If I make the return type nullable, then when I .map(_userFromFirebaseUser) I'm getting an error that says "The argument type 'Users? Function(User)' can't be assigned to the parameter type 'Users Function(User?)'." Users? _userFromFirebaseUser(User…