'Smart cast (automatic type promotion) using 'is' is not working
I'm using the Bloc pattern and have the following code to define my states:
import 'package:meta/meta.dart'
@immutable
abstract class UiState {}
class Loading extends UiState {}
class Success extends UiState {
Success(this.message);
final String message;
}
class Failure extends UiState {}
I try to use a UiState as follows:
class MyWidget extends StatelessWidget {
const MyWidget({
Key key,
@required this.uiState,
}) : super(key: key);
final UiState uiState;
Widget build(BuildContext context) {
if (uiState is Success) {
return Text(uiState.message);
}
...
}
}
But VSCode tells me that "The getter 'message' isn't defined for the class 'UiState'".
I've used smart casts before and they did work. But in this instance, I'm not able to figure out why it's not working.
My pubspec has the following:
environment:
sdk: ">=2.1.0 <3.0.0"
So, I assume my dart version is atleast 2.1.0.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
