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

Unhandled Exception: type 'Null' is not a subtype of type 'List' in type cast

Objective is to convert a String to List using map and return the value to a function call. I am using SharedPreferences to save a list of object called where in I save the data at a point and get the data when it is to be put on view. The below…
3
votes
2 answers

xcodebuild: WARNING: Using the first of multiple matching destinations:

Since I have migrated to null safety I am getting this error. I have done some research and try the solutions proposed, but none of them are working. Before the null safety, the application was running perfectly fine. I do not see the link between…
Laurent Thomas
  • 232
  • 4
  • 24
3
votes
3 answers

flutter problem : How to convert this type of double from string?

I want to convert sting to double , here my double is saperated by comma, So how to do it? void main() { var myInt = int.parse('12345'); assert(myInt is int); print(myInt); // 12345 print(myInt.runtimeType); // int var myDouble =…
Deepak
  • 1,664
  • 3
  • 19
  • 52
3
votes
1 answer

Flutter Error: StreamProvider requires initialData parameter after null-safety added. StreamProvider from firebase

since the Flutter null-safety update, my old code was broken. I managed to fix most of it, but this bit is still unresolved. Here is the code first: class _MyAppState extends State { @override Widget build(BuildContext context) { …
gjs
  • 183
  • 4
  • 14
3
votes
2 answers

*[SEVERE]* Failed to precompile build script .dart_tool/build/entrypoint/build.dart. This is likely caused by a misconfigured builder definition

[INFO] Precompiling build script...... [WARNING] ../../flutter/.pub-cache/hosted/pub.dartlang.org/gql_code_builder-0.2.0/lib/src/ast.dart:618:12: Error: A non-null value must be returned since the return type 'Expression' doesn't allow…
Hemedi
  • 33
  • 1
  • 5
3
votes
3 answers

The argument type 'String? Function(String)' can't be assigned to the parameter type 'String? Function(String?)?'

I am trying to setup password and email validation and I am getting the error above. Any help would be greatly appreciated. The error above is in the main.dart code and has been bolded in the code. validator.dart code enum FormType { login, register…
3
votes
1 answer

Migrating to Dart null safety: best practice for migrating ternary operator null checks? Is a monadic approach too unconventional?

I'm migrating a code base to null safety, and it includes lots of code like this: MyType convert(OtherType value) { return MyType( field1: value.field1, field2: value.field2 != null ? MyWrapper(value.field2) : null, ); } Unfortunately,…
jjoelson
  • 5,771
  • 5
  • 31
  • 51
3
votes
3 answers

Don't execute assignment if value is null

I am still coming up to speed with dart and wanted to know if there was an easier way to not execute a statement if the value is null. See example below: I can always do the if statements below for setting field3 and field4, but felt like something…
3
votes
1 answer

The argument type 'SomeType?' can't be assigned to the parameter type 'SomeType'

I get an error when trying to call a function: The argument type 'SomeType?' can't be assigned to the parameter type 'SomeType' How do I fix this?
jamesdlin
  • 81,374
  • 13
  • 159
  • 204
3
votes
2 answers

FLUTTER Error: Method 'copyWith' cannot be called on 'TextStyle?' because it is potentially null

Wow I have a whole lot of these: Error: Method 'copyWith' cannot be called on 'TextStyle?' because it is potentially null. 'TextStyle' is from 'package:flutter/src/painting/text_style.dart'…
Sam
  • 1,659
  • 4
  • 23
  • 42
3
votes
1 answer

Is there any way to migrate specific set of files from Flutter Project's code to null safety?

I recently migrated one project to null-safety (From Flutter SDK 2.2.3 to 2.8.1), but I have some more code in same project coded without null-safety on different branch in my git. Now I want to migrate that code. But I am not able to do it with…
Milan Surelia
  • 884
  • 1
  • 8
  • 18
3
votes
1 answer

error: The argument type 'String?' can't be assigned to the parameter type 'String', but null check doesn't work

I'm new to dart and flutter and I got this error: error: The argument type 'String?' can't be assigned to the parameter type 'String'. This error occurred when I tried to get fields of a user object from firebase and pass it to the User constructer.…
01D5D
  • 31
  • 1
  • 2
3
votes
3 answers

Why am i having problem with my toggle button

Hello guys I am total new to flutter so I was trying to build a BMI calculator , so i was trying to create a toggle switch between "MALE" and "FEMALE", so that when one card is clicked the other becomes inactive and i was trying to use a ternary…
3
votes
1 answer

How to set up sqlite database in flutter with null safety?

I've been struggling for a while to set up a sqlite database with sqflite in flutter. Code is producing a new instance of the database every time I call the getter method for a database. Here is the code: class DatabaseProvider { …
Mayketi
  • 93
  • 11
3
votes
1 answer

Flutter: How to handle "The default value of an optional parameter must be constant"

I have a simple class like this: class Restaurant{ final String id; final String name; List servingList; Restaurant({ required this.id, required this.name, this.servingList = [], // ERROR }); } By default I want an…
Dalon
  • 566
  • 8
  • 26