Reputation: 512286
Supposedly Dart 2.14 included the triple shift operator (>>>
), but when I try to use it I get an error:
print(0xff >>> 1);
The compiler highlights the last >
of the three and says:
Expected an identifier.
This is true on my local machine and in DartPad. Both are using the version of Dart 2.14 shipped with Flutter 2.5.
Am I doing something wrong or is this a problem with the release?
Upvotes: 2
Views: 842
Reputation: 6321
If you compile this code, required Dart SDK version 2.14.1.
Dart language site’s documentation and examples use version 2.13.4 of the Dart SDK. https://dart.dev/tools/sdk.
So when you are trying with Flutter, It uses SDK version less than 2.14.1.
Download the latest Flutter SDK https://flutter.dev/docs/get-started/install/windows and replace the old one. Update your pubspec.yaml file
environment:
sdk: ">=2.14.0 <3.0.0"
To run your code without Flutter app:
Download latest Dart SDK from https://dart.dev/tools/sdk/archive
Create a project with Android Studio IDE.
Create a new Flutter project. Select Dart from the left menu.
Locate Dart SDK path, that you downloaded(Must be extracted)
Provide your project name and location.
Create a Dart file and write these lines of code.
void main() {
final value = 0x22;
print("Current value : $value");
print("Unsigned shift right value is : ${(value >>> 4)}");
}
Output is
F:/Dart/dart-sdk/bin/dart.exe --enable-asserts F:\Flutter\TestDartLanguage\main.dart
Current value : 34
Unsigned shift right value is : 2
Process finished with exit code 0
Enjoy happy coding. Thanks
Upvotes: 0
Reputation: 126834
You can refer to my related answer here.
Any language features that are introduced in a given version require that version as the minimum constraint for your project. This means you need to update your pubspec.yaml
:
environment:
sdk: '>=2.14.0 <3.0.0'
Now, you can use:
var foo = 42;
foo >>> 2;
Upvotes: 4