Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

optional new and const in Dart 2

Tags:

dart

i created a simple stand alone application using the dart sdk provided in the flutter sdk

and if i run this code

main() {
  MyClass myObj=MyClass();
}
class MyClass{

}

NoSuchMethodError: Attempted to use type 'MyClass' as a function. Since types do not define a method 'call', this is not possible. Did you intend to call the MyClass constructor and forget the 'new' operator?

flutter --version

  • Flutter 0.3.2 • channel beta • https://github.com/flutter/flutter.git
  • Framework • revision 44b7e7d3f4 (3 weeks ago) • 2018-04-20 01:02:44 -0700
  • Engine • revision 09d05a3891
  • Tools • Dart 2.0.0-dev.48.0.flutter-fe606f890b

so what i am doing wrong here ? i want to get the optional new and const

like image 469
Raouf Rahiche Avatar asked Jan 28 '26 09:01

Raouf Rahiche


1 Answers

flutter version doesn't matter if you have a Dart standalone app. dart --version prints the relevant information.

You need to run with --preview-dart-2 until Dart 2 semantics becomes default. In Flutter this is already the default.

dart --preview-dart-2 bin/main.dart 

In IntelliJ you can pass this option in "Run/Debug Configurations" > "VM options".

This will become the default soon in standalone Dart as well.

enter image description here

like image 193
Günter Zöchbauer Avatar answered Feb 03 '26 07:02

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!