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

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 the name 'FutureOr'

Looks like import is missing import 'dart:async';
FutureOr is part of dart:async

Related

Target of URI doesn't exist: 'package:flutter/material.dart'

I've just set up my Windows 11 for Flutter development,
So I updated flutter SDK, and placed it in my Documents. After, I got this:
Target of URI doesn't exist: 'package:flutter/material.dart'.
The function 'runApp' isn't defined.
Classes can only extend other classes.
The name 'WidgetBuilder' isn't a type so it can't be used as a type argument.
Undefined class 'Widget'.
Undefined class 'BuildContext'.
The method 'MaterialApp' isn't defined for the type 'MyApp'.
The method 'ThemeData' isn't defined for the type 'MyApp'.
Undefined name 'Colors'.
The method doesn't override an inherited method.
What is an error? It's difficult to me.
Try running the following command in terminal:
flutter pub get

Why getting The method 'contains' isn't defined for the type 'String'. flutter

I am using contains method for a string in dart but getting an error like this.
can anyone tell me what is wrong with using .contains for a string in dart
This is my code
String isPdf = "https://www.africau.edu/images/default/sample.pdf";
isPdf.contains("pdf");
Error occurs
The method 'contains' isn't defined for the type 'String'.
Try correcting the name to the name of an existing method, or defining a method named 'contains'.
In vscode quickfix tells me that
change the 'contains' method to 'oscontains'.

The argument type 'JsObject' can't be assigned to the parameter type 'BuildContext'.dart

I am getting an error it is saying "The argument type 'JsObject' can't be assigned to the parameter type 'BuildContext'.dart"
error on this part Navigator.of(context).pop()
It looks like you've imported by mistake the dart:js module. If so, just remove it:
import 'dart:js'; // <- Remove this import
The dart:js module exports a global context of type JsObject and its type conflicts with the BuildContext type.

The getter 'value' isn't defined for the type BehaviorSubject<>

After I updated the code to adapt flutter null safety the code below gaves me the error
The getter 'value' isn't defined for the type
'BehaviorSubject'.
final _brightness = BehaviorSubject<Brightness>();
...
if (_brightness.value == Brightness.light) { ... } // error is here
How to get value from BehaviorSubject then?
Using rxdart: ^0.26.0
This is because the value getter is not implemented by BehaviorSubject class this function belongs to ValueStreamExtensions file which itself is an extension method file on the ValueStream class which BehaviorSubject is implemented by if you wish to use extension function of any type in your code you should first import the extension file into to your code file in this case just add
import 'package:rxdart/src/streams/value_stream.dart';
also, note that for using the BehaviorSubject class your should import that too
import 'package:rxdart/src/subjects/behavior_subject.dart';
or directly import the main Rx library file which imports other dependencies you may wanna use in your code like this " This is the recommended way "
import 'package:rxdart/rxdart.dart';
also, BehaviorSubject itself has a getter which is called valueWrapper that holds the latest value of your subject and you can directly use this getter
here is more information about extension methods in dart
https://dart.dev/guides/language/extension-methods
The Code you provided reads like you want to get the value from a Brightness Instance which is stored in the BehaviorSubject.
https://pub.dev/documentation/rxdart/latest/rx/BehaviorSubject-class.html
A special StreamController that captures the latest item that has been added to the controller, and emits that as the first item to any new listener.
Your _brightness variable is not from type Brightness its of type BehaviorSubject.
So you have to subscribe with a listener to it and you will get the latest value which has been added to the BehaviorSubject.

Flutter "argument type not assignable" Error with two identical types

Flutter shows me this error, but the two types are identical.
[CartItem it's just a simple model; there was a conflict since another widget had the same name but I resolved it using "as" in the import statement]
The argument type List<CartItems> (where CartItem is defined in /Users/marco/Documenti Locali/shop_app/lib/providers/cart.dart)' can't be assigned to the parameter type List<CartItems> (where CartItem is defined in /Users/marco/Documenti Locali/shop_app/lib/providers/cart.dart)'.dartargument_type_not_assignable
list.dart(56, 16): List is defined in /Users/marco/flutter/bin/cache/pkg/sky_engine/lib/core/list.dart
cart.dart(3, 7): CartItem is defined in /Users/marco/Documenti Locali/shop_app/lib/providers/cart.dart
list.dart(56, 16): List is defined in /Users/marco/flutter/bin/cache/pkg/sky_engine/lib/core/list.dart
cart.dart(3, 7): CartItem is defined in /Users/marco/Documenti Locali/shop_app/lib/providers/cart.dart
Peek Problem (⌥F8)
No quick fixes available
It was a double slash in the import statement that generated this strange error.
you should use the library prefix in the usage too so if your namespace is
import 'package:app/xxxx/shop_app/lib/providers/cart.dart as shop_cart;
you should specify it in the generic List as well such as;
List shopCarts = etc...;
Check your import statement at the top of file even if you mistyped a directory folder name as 'Caps or Small' you can get this error.