Home > database >  What does colon mean when importing core libraries in Dart?
What does colon mean when importing core libraries in Dart?

Time:08-19

What does colon mean when importing core libraries in Dart?

import 'dart:math';

I haven't find any resources that tells what does that mean.

CodePudding user response:

You should use colon when you try to import other packages modules... You can omit it when the module that you are importing is in the same package.

import '<package>:<module>'; // normal import
/* 
  if the module is the in the same package of the file where i'm importing it 
*/
import '<module>';

CodePudding user response:

From the documentation (emphasis mine):

Using libraries

Use import to specify how a namespace from one library is used in the scope of another library.

For example, Dart web apps generally use the dart:html library, which they can import like this:

import 'dart:html';

The only required argument to import is a URI specifying the library. For built-in libraries, the URI has the special dart: scheme. For other libraries, you can use a file system path or the package: scheme. The package: scheme specifies libraries provided by a package manager such as the pub tool. For example:

import 'package:test/test.dart';

Note: URI stands for uniform resource identifier. URLs (uniform resource locators) are a common kind of URI.

  •  Tags:  
  • dart
  • Related