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

Flutter Unhandled Exception in null ckeck operator

I am using a very simple class as a SharedPrefs handler in my futter app, class SharedPrefsHandler { SharedPreferences? _sharedPrefs; SharedPrefsHandler() { _sharedPrefs ?? _getSharedPrefs(); } Future _getSharedPrefs() async { …
codeKiller
  • 5,493
  • 17
  • 60
  • 115
0
votes
3 answers

Migrating to null safety: The argument type 'Object?' can't be assigned to the parameter type 'List'

After migrating to null safety I'm getting an error on ListView as "The argument type 'Object?' can't be assigned to the parameter type 'List'." I'm getting error on return ListView(children: snapshot.data,); Can anyone help me to fix this error…
0
votes
1 answer

Flutter Null check operator used on a null value

_stores is giving me issue where if value.stores is null, I get the below null error. how to resolve this issue ? null-safety enabled as this project is 2.12.2 plus. Code: dynamic _stores = useProvider( …
princeoo7
  • 1,071
  • 3
  • 21
  • 44
0
votes
1 answer

Why is one way of json to object working and the other throwing null error? Dart/Flutter null safety trouble

I'm learning how to use json, not used to Dart null safety & I don't like it so far. But I will have no choice but to adapt to it. I'm trying to parse my json object list into a list of objects. I was able to work out the basics in my main, but when…
RobbB
  • 1,214
  • 11
  • 39
0
votes
1 answer

Flutter project not running after successful migration to null safety

I have problem running flutter project after successful migration to null safety. I use android studio. Here is the result of flutter doctor: Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 2.2.1, on…
M.R.M
  • 540
  • 1
  • 13
  • 30
0
votes
2 answers

The return type 'LoginPage' isn't a 'void', as required by the closure's context

so, if user is null.. page is move into login page Widget build(BuildContext context) { AuthServices.userStream.listen((User? user) { if (user == null) { return LoginPage(); } }); }
0
votes
1 answer

Nullable values using flutter 2.+

I have created a model class to use with dio library and fetch data , and in flutter 2.+ , they have introduced null safy , when i created the model class i got error to make values nullable , it worked with primitive types by adding ? but for the…
Taki
  • 3,290
  • 1
  • 16
  • 41
0
votes
1 answer

Flutter: A value of type 'GoogleSignInAccount?' can't be assigned to a variable of type 'GoogleSignInAccount'

I am trying to connect my flutter application with firebase google authentication. The error states "The property 'authentication' can't be unconditionally accessed because the receiver can be 'null'. Try making the access conditional (using '?.')…
0
votes
1 answer

Unhandled Exception: Unhandled error Null check operator used on a null value occurred in Instance of 'AuthBloc' in flutter

I know, many people have asked similar questions regarding this, here. But no solution is working for me, and I'm unable to understand the solution. So please someone help me out. I declared the variable user to be non-null (by adding exclamation…
Shreyansh Sharma
  • 1,588
  • 2
  • 17
  • 42
0
votes
1 answer

How to fix error: "Null check operator used on a null value"?

I'm getting a Null check operator used on a null value error in flutter. Map newUserMap = jsonDecode(authenticate.body); print('newUserMap?'); var authNodeUser = TokenContent.fromJson(newUserMap); print('authNodeUser?'); String?…
Meggy
  • 1,491
  • 3
  • 28
  • 63
0
votes
1 answer

The initializer type 'AuthRepository?' can't be assigned to the field type 'AuthRepository' in flutter

The error is coming on line 6 (in the first code snippet or the main code part), on authRepository part. The main code - class AuthBloc extends Bloc { final AuthRepository _authRepository; var v; AuthBloc({ @required…
Shreyansh Sharma
  • 1,588
  • 2
  • 17
  • 42
0
votes
1 answer

Shorthand of checking the nullability of a bool variable used in an if condition

Future f() async => true; void main() async { final proceed = await f(); if (proceed) {...} // Error if (proceed != null && proceed) {...} // Works but too verbose } Is there any shorthand or a better way of proceeding instead of…
iDecode
  • 22,623
  • 19
  • 99
  • 186
0
votes
2 answers

Error: 'split' can't be unconditionally invoked because the receiver can be 'null'

Android Studio throws this following NullSafety error on split in Flutter. The method 'split' can't be unconditionally invoked because the receiver can be 'null'. Try making the call conditional (using '?.') or adding a null check to the target…
Meggy
  • 1,491
  • 3
  • 28
  • 63
0
votes
1 answer

What's the use of PreferredSize widget after null safety?

Before null-safety I could do: class FooBar extends PreferredSize { final String data; FooBar(this.data); @override Size get preferredSize => Size.fromHeight(100); @override Widget build(BuildContext context) { return…
iDecode
  • 22,623
  • 19
  • 99
  • 186
0
votes
2 answers

How to create ElevatedButton from RaisedButton?

There are so many properties in the RaisedButton whose equivalent I can't find yet in the ElevatedButton. So, how can I convert or replicate a RaisedButton (with all the properties) to the new ElevatedButton? Like: RaisedButton( onPressed: () {}, …
iDecode
  • 22,623
  • 19
  • 99
  • 186