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

RangeError (index): Invalid value: Not in inclusive range 0..12: 13 during flutter null-safety migration

I'm following this guide to migrate my flutter project to null safety. At step 2 when issuing the command $ dart migrate Also I'm wondering if it's normal that there are no issues found during project analysis: Migrating…
Christian
  • 43
  • 4
4
votes
3 answers

Flutter formKey currentstate is null when pass to another widget

I'm trying to create a Textbutton widget with a disabled property like this: class AppTextButton extends StatelessWidget { final String title; final void Function(BuildContext context) onPress; final EdgeInsetsGeometry margin; final…
hrtlkr29
  • 383
  • 1
  • 7
  • 21
4
votes
2 answers

The library 'package:splashscreen/splashscreen.dart' is legacy, and should not be imported into a null safe library

The imports I am using: import 'package:flutter/material.dart'; import 'package:splashscreen/splashscreen.dart'; import 'package:imagetotext/homePage.dart'; However, the linter is giving me the following warning: The library…
4
votes
4 answers

Use a non null saftey package inside a null saftey enabled app dart

So , there is this package which doesn't have null safety in any of its versions. Is there any way i can use it inside my project where i am using null safety. Here is the error that my IDE is showing me :
Farhan Syedain
  • 408
  • 3
  • 12
4
votes
4 answers

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

class StudentValidationMixin { String validateFirstName(String value) { if(value.length<2){ return 'İsim en az iki karakter olmalıdır'; } } } The body might complete normally, causing 'null' to be returned, but the return…
Fatih Sakar
  • 43
  • 1
  • 4
4
votes
2 answers

non-null variable in flutter test

I was learning flutter about year ago and now im coming back after a break but i counter a problem, it's probalby pretty simple but i dont really understand it. Im following a tutorial on Flutter Clean Architecture and when i'm writing my first test…
aleksander frnczak
  • 399
  • 1
  • 2
  • 12
4
votes
1 answer

Flutter The name FutureOr isn't a type, so it can't be used in an as expression

While upgrading the flutter project to null-safety it has appeared the following error The name 'FutureOr' isn't a type, so it can't be used in an 'as' expression. Try changing the name to the name of an existing type, or creating a type with…
Javeed Ishaq
  • 6,024
  • 6
  • 41
  • 60
4
votes
1 answer

How to initiate WebViewController in flutter

I was trying to declare a variable in class level as below: WebViewController _webViewController = WebViewController(); sothat I can reuse that in other functions.But for nullsafety issue I tried to initialize it, but showing doesn’t have a default…
the-a-monir
  • 147
  • 1
  • 10
4
votes
2 answers

unexpected null value Flutter

hey guys i m new in dart and flutter when i run the project i face an error that says unexpected null value i couldn't find where is the mistake, i think the problem is in Null Safety. I have three classes two of them are for screen and one is a…
Boukhames Karim
  • 53
  • 1
  • 1
  • 3
4
votes
2 answers

Dart null safety conditional statement?

So I have a class Cache which has a method compare that returns a bool. I have an instance of this class that is nullable. Cache? recent; I want to executed a piece of code when recent is not null and compare returns false Without null safety I…
coder_86
  • 95
  • 2
  • 13
4
votes
1 answer

Is there a way to check if late variable has been initialized

I'm migrating to null safety and have some setters that executes code if a value changes set someValue(int value) { if ( _someValue != val ) { _someValue = val; // do some stuff } } Some of my variables now have late…
buttonsrtoys
  • 2,359
  • 3
  • 32
  • 52
4
votes
0 answers

hooks_riverpod: Flutter Firebase auth with Riverpod, error occur: a provider tried to assign `null` to a non-nullable `exposedvalue`"

I try to implement Firebase Auth for Flutter according to this tutorial: https://youtu.be/vrPk6LB9bjo?t=393 The Widget should check whether the user is login using riverpod hook method and provider and load either HomeScreen or LoginScreen…
asian_gang
  • 51
  • 4
4
votes
3 answers

type 'List' is not a subtype of type 'List' in type cast

After running dart migrate & applying null safety, that error popped up at my code and I think that's the error causing code block. LayoutBuilder(builder: (context, cons) { return GestureDetector( child: new Stack( children: [ …
3
votes
3 answers

Dart/Flutter convert a fraction string to a double

If I have a fraction double stored as a string i.e., "16/9", "16 / 9", "9/16", "9 / 16", etc., how can I convert it to a double? Or should I store those differently in order to convert them to doubles to be used as aspectRatio settings? Code…
Matt Larsuma
  • 1,456
  • 4
  • 20
  • 52
3
votes
0 answers

Flutter Error: Unexpected null value in debug console

I am using where clause to filter out what user is typing with the api result but I am getting Error: Unexpected null value. I am using a post request. this is my model :- class SearchSquad { SearchSquad({ required this.count, required…