Clint
Clint

Reputation: 1094

Why is ".dart" needed for import?

When you import a package, you do:

import 'package:pkg_name/some_package.dart';

Why is .dart needed? Can you import files other than .dart?

Upvotes: 1

Views: 66

Answers (1)

Pixel Elephant
Pixel Elephant

Reputation: 21383

You can have a file ending in a non .dart suffix and import it. For example if you had the following in example.nondartsuffix:

String foo() => 'foo';

You could import it with import 'example.nondartsuffix' and it would work. However, that's not particularly useful, since it still must be valid Dart code.

The current import syntax is pretty verbose, and there is an open issue for improving it (removing the .dart suffix along with some other suggestions).

Upvotes: 2

Related Questions