I imported math.

import 'dart:math'; 

But how can I call "PI" constant?

This is not working.

 math.pi / 12.0 

3 Answers

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

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.

0

First import 'dart:math'; then use pi/12.0 instead of it should work fine.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.