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

How to pass data dynamically to a Widget class inside Model

I have a model like this: class MyModel{ Widget widget; MyModel(this.widget); } var myPage = MyModel(HomeWidget()); is there a way to pass data to HomeWidget() using model when i use it? like this? myPage.widget("some data") or any way to…
2
votes
1 answer

Dart compare int null safety issue : operator can't be unconditionally invoked because the receiver can be 'null'

I have an object of class State it contains a nullable list called playList and a nullable player object. when I try to write this if statement if(state.playList?.length > 0 && state.player?.currentIndex? >0) I got this error The operator '>'…
Shady Mohamed Sherif
  • 15,003
  • 4
  • 45
  • 54
2
votes
3 answers

Another exception was thrown: type '() => Map?' is not a subtype of type 'Map' in type cast

While returning Future builder am getting this error . . Another exception was thrown: type '() => Map?' is not a subtype of type 'Map' in type cast how do i resolve?? Thanks in advance. return…
ThE 2K KiD
  • 43
  • 1
  • 5
2
votes
1 answer

Getting error in flutter google_maps_place_picker | isFromMockProvider() in Location has been deprecated

Not sure where I made mistake but I got an error while implementing google_maps_place_picker: any error: warnings found and -Werror…
2
votes
0 answers

How to solve "error: The method 'lengthSync' and 'openRead' isn't defined for the type 'FilePickerResult'" in flutter?

I want to upload multiple image to the google drive. I am using flutter null safety version and using one example https://www.c-sharpcorner.com/article/google-drive-integration-in-flutter-upload-download-list-files/ . In above example the writer is…
2
votes
1 answer

Flutter error: The argument type 'DocumentSnapshot? can't be assigned to parameter 'DocumentSnapshot

I get this Errorcode when I try to run my flutter app and I don't know how to solve it please help: Error: The argument type 'DocumentSnapshot?' can't be assigned to the parameter type 'DocumentSnapshot'…
tobsq
  • 27
  • 4
2
votes
1 answer

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

In Book : Flutter Apprentice First Edition, I had below code: import 'package:flutter/painting.dart'; // 1 enum Importance { low, medium, high } class GroceryItem { // 2 final String id; // 3 final String name; final Importance importance; final…
abhimanyu
  • 157
  • 1
  • 1
  • 11
2
votes
0 answers

How is the 'id' Field Handled by SQFlite Flutter Package During an Insert?

This question has to do with the sqflite Flutter package, the "id" field, and how that affects null safe coding choices in the data model. Consider the following (working fine) code: class User { final int? id; final String name; final int…
Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100
2
votes
1 answer

Flutter: Dart Convert properly null safety my class

How to change my class for null safety compliant? My error for converting my project to null safety. error • The parameter 'bloc' can't have a value of 'null' because of its type, but the implicit default value is 'null'…
user3701584
  • 115
  • 2
  • 8
2
votes
1 answer

Getting this Error RangeError (Index) Invalid Value: not in Exclusive Range 0..2 : 5 previou

previously I was getting the of setState() or markneedsBuild() Called during the build for solving this error I call a function initState() now I am getting the range error. whos is going to solve this I'm in learning paise I don't know enough…
2
votes
0 answers

How can I do circle transform carousel with Flutter?

I want to make Circle Carousel Slider as pictured. How can I do this using CarouselSlider? I'm trying to do this but not all Carousel packages work this way or have a null safety feature.
2
votes
3 answers

Flutter 2.5.1 - Could not build the application for the simulator

I migrated my project from Flutter 1 to 2.5.1, and I countered this error Result: In file included…
AgentRed
  • 62
  • 5
  • 36
2
votes
2 answers

The property 'quantity' can't be unconditionally accessed because the receiver can be 'null'. Try making the access conditional (using '?.')

Relevent code import 'package:flutter/foundation.dart'; class CartItem { final String id; final String title; final int quantity; final double price; CartItem({ required this.id, required this.title, required this.quantity, …
TheTechGuy
  • 16,560
  • 16
  • 115
  • 136
2
votes
3 answers

Non-nullable instance field ['controller'] must be initialized in flutter

Good day! I am a new to Flutter to would like to start my Startup but I was trapped in this problem to make Tabbar example... I have almost been frustrated all day because of this problems.... Dart Analysis keeps saying this below.... Non-nullable…
2
votes
2 answers

flutter form validator with null safety

i got a problem while trying to make a form validator on my login screen it just doesn t work when i tape login and the text field is already null. here s my code if u have any help, i m down to : TextFormField validate parameter takes a function…