How to use the PI constant in Dart
As an alternative to the accepted answer, you can keep importing without a prefix, and reference pi
as just pi
:
import "dart:math" show pi;
main() {
print(pi / 12);
}
This works just as well as prefixing. It's a matter of taste which one you prefer.
First import 'dart:math';
then use pi/12.0
instead of math.PI/12.0
it should work fine.
you should
import 'dart:math' as math;
instead of just import 'dart:math';
because when you use the as
keyword you provide the imported library a name so you can reference it anywhere in your file